When updating a stateful component in React is it considered a bad practice when a component uses the current state to update the new state.
For example if I have a class that stores whether a filter is open or not in it's state, is one of these options for updating the state more desirable than the other in terms of performance?
Option 1:
class Container extends Component {
state = {
show: false
}
show = () => this.setState({ show: true })
hide = () => this.setState({ show: false })
render() {
<ExternalComponent
show={this.show}
hide={this.hide}
/>
}
}
Option 2:
class Container extends Component {
state = {
show: false
}
toggleVisibility = () => this.setState({ show: !this.state.show })
render() {
<ExternalComponent
toggleVisibility={this.toggleVisibility}
/>
}
}
Option 3:
class Container extends Component {
state = {
show: false
}
setShow = (newVal) => this.setState({ show: newVal })
render() {
<ExternalComponent
setShow={this.setShow}
/>
}
}