I read an article that creating small reusable components decreases the file size, makes unit testing faster and easier and a lot more. So I'm now trying to create one, however I am very new to reactjs and I'm maintaining this project for a friend, so I haven't written all the code.
Heres a code snippet:
class ObjectKeyDisplay extends Component {
constructor(props) {
super(props)
this.state = { open: false } // Sets open to false (closed)
}
renderInner() {
const { schema, parentDocumentId, collectionName, value } = this.props
const { open } = this.state // equals const open = this.state.open
let expandButton
if (schema.type === 'belongs_to') {
expandButton = (
<button onClick={e => this.setState({ open: !open })}> // Sets it to true (opened)
{open ? 'Minimera' : 'Expandera'}
</button>
)
}
So I basically want to make the whole open/close process to a component, so I easily reuse the logic for other buttons. I would really appreciate if someone could help me out here!