I want to check cookie on page load in react. After the page load the function checkCookie not executed because the console.log inside the function not appear in console. how to execute the checkCookie? Here my code :
import React, { useState } from "react";
import { useCookies } from "react-cookie";
function App() {
const [cookies, setCookie, removeCookie] = useCookies(["janganTampil"]);
const [isCookieSet, setIsCookieSet] = useState(false);
// state for modal
const [show, setShow] = useState(false);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
function checkCookie() {
const tampil = cookies.janganTampil === 'true';
if (tampil) {
setIsCookieSet(true);
} else {
handleShow();
}
console.log(isCookieSet);
console.log(show);
}
return (
<div onLoaded={checkCookie} className="App">
...
{/* Tutorial is modal */}
<Tutorial isCookieSet={isCookieSet} setIsCookieSet={setIsCookieSet} cookies={cookies} setCookie={setCookie} removeCookie={removeCookie} handleClose={handleClose} show={show} ></Tutorial>
</div>
);
}
export default App;