0
I’m trying to make a condition where the active component depends on a state variable.
this.state = {
display: 0,
}
The state 0 is the initial state, which is changed when the user clicks a button.
Depending on the button the display variable will change to a value from 1 to 4.
{if (this.state.display == '0') {
return ()
} else if (this.state.display == '1') {
return()
} else if (this.state.display == '2') {
return()
} else if (this.state.display == '3') {
return()
} else if (this.state.display == '4') {
return(
<Catalogo></Catalogo>
)}
}}
The full code is in github/cmoutella
Error says 'Parsing error: Unexpected token' and points to if.
How can I do this?
for testing purposes I put to return <div></div> on those who had not yet returned the component, but the error persists. Googling found that React does not support if Else.
– cmoutella
the updated code: https://github.com/cmoutella/cmoutella.github.io/blob/issues/03/temporario/hinode/src/App.js
– cmoutella