I have project in ReactJS in that I have 3 types of different views to show data. For that I have 3 different component.
I have one parent component in which I have one button called Rotate and three options two change view.
My requirement is I need to set visibility of Rotate button based on view types like for ViewType1 rotate button should be visible and for other types of views rotate button should be hidden.
Below is my code:
Parent Component
class ParentView extends Component {
constructor(props) {
super(props);
this.state = {
isViewType1: true
};
this.setRotateButtonVisibility = this.setRotateButtonVisibility.bind(this);
}
setRotateButtonVisibility(isType1) {
this.setState({isViewType1 : isType1});
}
render() {
return(
{this.state.isViewType1 && (
<button id="btnRotate" className="btn btn-default">Rotate</button>)
}
<Switch>
<Route
exact
path="/project/:projectID"
render={() => (
<Viewtype1/>
)}
/>
<Route
exact
path="/project/:projectID/ukeyview"
render={() => (
<Viewtype2/>
)}
/>
<Route
exact
path="/project/:projectID/proxystructureview"
render={() => (
<Viewtype3/>
)}
/>
</Switch>
)}
So, how to call setRotateButtonVisibility() function based on view types?
OR
How to set state based on view types?
I have tried callBackFunc of child component but it is not allowing to change state.
I have tried following code also:
<Route
exact
path="/project/:view
{...this.setRotateButtonVisibility(false)}
render={() => (
<Viewtype3/>
)}
/>
but nothing is working properly.