receiving error of setcount is not a function.
i’m newbie please help me
import React, { memo, useState } from "react";
export const Container = memo(function Container() {
const { count, setCount } = useState(0);
return (
<div>
{count}
<button onClick={()=>setCount(count+1)}>Increase</button>
</div>
);
});
>Solution :
useState doesn’t return an object which you’re destructuring.
It returns an array of two values i.e. value and a function.
You should read React useState docs
It returns a pair of values: the current state and a function that
updates it. This is why we write const [count, setCount] = useState().
This is similar to this.state.count and this.setState in a class,
except you get them in a pair. – REACT DOCS
Change
const { count, setCount } = useState(0);
to
const [ count, setCount ] = useState(0);