Answer the question
In order to leave comments, you need to log in
How to solve setState problem in react?
there are two components, a button and a block, the default state of the block is false, when the button is clicked, the state should change, but this does not happen, an error pops up
×
TypeError: setState is not a function
onClick
C:/todoTest/todo-app/src/components/list-button/List-button.jsx:7
4 |
5 | const ListButton = ({items,setState}) => {
6 |
> 7 | return <button onClick={() => setState(true)} className="todo-header-plus" title="Создать список дел">
8 | {
9 | items.map((item,index) => (
10 | <i key={index}>{item.icon}</i>
View compiled
▶ 22 stack frames were collapsed.
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.
import React from 'react';
import './List-button.scss';
const ListButton = ({items,setState}) => {
return <button onClick={() => setState(true)} className="todo-header-plus" title="Создать список дел">
{
items.map((item,index) => (
<i key={index}>{item.icon}</i>
))
}
</button>
}
export default ListButton;
import React, {useState} from 'react';
import './List-popup.scss';
const AddList = () => {
const [state, setState] = useState(false);
return state && (<div className="list-popup">
<h1>123</h1>
</div>)
}
export default AddList;
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