Is this code syntactically correct? The effect I'm trying to achieve is for the text to appear once the button has been clicked...
import React, { useState } from 'react';
import './App.css';
function Example(){
const [state, setState] = useState({shows: false});
return(
<div>{state.shows && <p>hi</p>}
<button onClick={() => setState({shows: true})}>
Click me
</button>
</div>
)
}
export default Example;
showsandsetShows, and give the initial value directly, i.e.useState(false). Your render then would be<div>{shows && <p>...For more complex state and mutations useReducer is recommended.