score:1

Accepted answer
  • components must begin with an uppercase letter.

  • the code works, but when you click a link the page navigates. if you cancel the event it works as expected.

https://codesandbox.io/s/react-playground-forked-yiqre?file=/index.js

nutshell:

<nav.link
  href="/"
  onselect={(_, e) => {
    e.preventdefault();
    handletest(false);
  }}
>

cleaned up, with the navigation in place:

https://codesandbox.io/s/react-playground-forked-6vch3?file=/index.js

you're trying to do an spa, but it is not currently an spa. you navigate away from the page with the updated state. when the new page loads (/test) your state resets.

there's a variety of ways to create an actual spa where you define a component per page: you can use any of several routing solutions, there are hook-based solutions, etc.

plus there's no /test path in the code sandbox so it wouldn't know what to do anyway.


Related Query

More Query from same tag