I faced a strange issue when I randomly try to set true or false in useState using Math.random()
.
Example:
const [hasPrime] = useState(Math.random() < 0.5)
...
{hasPrime && (
<div>
<p>Free Next-day delivery</p>
</div>
)}
Error: Hydration failed because the initial UI does not match what was rendered on the server.
If I put in useState
true or false, I will not get such error.