I am new to React. Here is the problem. when I change the switch state I want to change the theme of whole app.
This is my switch component on the sidebar
constructor() {
super();
this.state = { checked: false };
this.handleChange = this.handleChange.bind(this);
}
handleChange(checked) {
this.setState({ checked });
console.log('ddd');
}
render() {
return (
<Switch
checked={this.state.checked}
onChange={this.handleChange}
onColor='#86d3ff'
onHandleColor='#0061ac'
handleDiameter={20}
uncheckedIcon={false}
checkedIcon={false}
boxShadow='0px 1px 5px rgba(0, 0, 0, 0.6)'
activeBoxShadow='0px 0px 1px 10px rgba(0, 0, 0, 0.2)'
height={10}
width={30}
className='react-switch'
id={this.props.id}
/>
);
}
and this is route component that contained by ThemeProvider
<ThemeProvider theme={{ mode: this.state.checked ? 'dark' : 'light' }}>
...
</ThemeProvider>
I want to change the whole app theme when I click on the switch. (Sorry for bad English)