Answer the question
In order to leave comments, you need to log in
How to make a boolean property toggle in a state?
function Toggle() {
let [state, setState] = useState({
fromBook: [
{ text: "Отрывок из книги 1" },
{ text: "Отрывок из книги 2" },
{ text: "Отрывок из книги 3" },
],
show: false,
id: 0,
});
function showExcerpt() {
let show = state.show;
setState({ show: !show });
console.log(state.show);
console.log(state.fromBook);
{/*После второго нажатия state.fromBook становится undefined:*/}
}
return (
<div>
<button onClick={showExcerpt}>Показать отрывок </button>
{/* <p>{state.excerpts[state.id].text}</p> */}
</div>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question