DEV Community

Raj
Raj

Posted on

state hook not a function

I got stuck on using state hook and keep getting state hook is not a function. Tried restoring all packages and used different syntax not sure what I am missing here. Getting error message setExactPage is not a function. Any help would be appreciated.

const [currentPage, setPrevPage, setNextNext, setExactPage] = useState(0);
const handleFirstProposalPage = () => { setExactPage(1) };

First Page: {currentPage}

Top comments (3)

Collapse
 
aqrojo profile image
aqrojo

As Jack says, this hook return only 2 values, a getter prop and a setter function
If you want to manage more than one value, I may recommend you the useReducer hook or something like useSetState hook:
github.com/streamich/react-use/blo...

Collapse
 
jackmellis profile image
Jack

Use state only returns 2 things: currentPage and setExactPage. The others you'll need to write yourself

Collapse
 
krisrajzlive profile image
Raj

Thanks