-1
My reactjs app only works if I remove the conditional. I figured it might be Babel’s fault, but if it was, JSX wouldn’t work even without parole.
App.js:
import React, {useState} from "react";
function App() {
const [ versao, setVersao ] = useState(0);
function alteraVersao() {
setVersao(versao + 1)
}
return (
{versao < 2 &&
<div>
<h1 className="titulo">Clicou {versao} vezes</h1>
<button onClick={alteraVersao}>acrescenta cliques</button>
</div>
}
)
}
export default App;
index js.:
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(
<App versao="2.0"/>,
document.querySelector("#root")
)
return versao < 2 && ( /* ... */ );
1) Remove the keys, since theversao < 2
is not inside JSX; 2) and place parentheses for JSX, since it occupies more than one line.– Rafael Tavares