Reputation: 3815
By mistake, I use CheckBox as a project name. I generate the React Native
project using react-native init CheckBox
. I need check box for multiple choice question. So, I install the check box library from here. Then, i import the library using import CheckBox from 'react-native-checkbox';
. Now the problem: Duplication declaration "CheckBox"
. What do i need to solve this ? Either I delete the project and generate new one. Or there is any way to solve this issue in current project ?
My code is :
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import CheckBox from 'react-native-checkbox';
class CheckBox extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});
AppRegistry.registerComponent('CheckBox', () => CheckBox);
Upvotes: 2
Views: 11093
Reputation: 4125
import SomethingElse from 'react-native-checkbox';
From my understanding, we can rename the import name which is come from the export default of a package, ex. 'react-native-checkbox.
Therefore just change the component name from react-native-checkbox to something else of CheckBox then it should solve the Duplication declaration problem.
Upvotes: 1
Reputation: 15616
You're importing a component called CheckBox
and then defining a new component with the same name. To fix this you'll need to rename your component that you define:
class CustomCheckBox extends Component
...
AppRegistry.registerComponent('CustomCheckBox', () => CustomCheckBox)
Upvotes: 0