This page is generated by getStaticPaths and getStaticProps to have [projectSlug].tsx,
The problem is that the <h1>{counter}</h1>
is modified when the state changes but the condition is not affected by the change.
const [counter, setCounter] = useState(0);
<>
<h1>{counter}</h1>
{counter % 2 === 0 ? (
<div> Hola 1 </div>
) : (
<div> Hola 2 </div>
)
}
</>
I have not been able to find any kind of solution.
2
Answers
There is no need for round braces around conditionally rendered div elements. Remove them and see if it sovles the issue.
I test that code.
It run. restart your computer and retest it.
You may use getStaticProps for default value of useState on builds?
If you use getStaticProps that page code only one use when compiler build it.
so if getStaticProps’s parameter is changed, page isn’t changed.
if that reason, you need to change getStaticProps to getServerSideProps or get parameter slug or SWR so on.