24
loading...
This website collects cookies to deliver better user experience
const posts = useSelector((state) => state.posts)
// retrieves what is stored in state.posts and makes it available // in posts.
const comments = useSelector((state) => state.comments)
// both posts and comments are accessible in their respective
// variables within the scope of this functional component
const [showForm, setShowForm] = useState(false)
false
to the useState hook. Now, our falsey value will persist, and is accessible by calling our showForm variable. "setShowForm(!showForm)" will set the value of showForm, mimicking a change of state, locally, within our component. function Post(props){
const [showForm, setShowForm] = useState(false)
return(
<button onClick{() => setShowForm(!showForm)}> Show Form </button>
{ showForm ? <Commentform id={props.id} /> : showForm}
)
}