ctrlplusb / react-universally

A starter kit for universal react applications.
MIT License
1.7k stars 244 forks source link

Counter goes back to zero when switching to different page #453

Closed c0debreaker closed 7 years ago

c0debreaker commented 7 years ago

It's the first time I've tried this. I wish on terminal, there was an instruction Open http://localhost:1337 in your browser. It just said Server listening on port 1337. I wasn't sure if react-universally runs 2 services(a client and api).

$ cross-env DEPLOYMENT=development babel-node internal/development
==> VENDORDLL -> Generating a new "client" Vendor DLL for boosted development performance.
The Vendor DLL helps to speed up your development workflow by reducing Webpack build times.  It does this by seperating Vendor DLLs from your primary bundles, thereby allowing Webpack to ignore them when having to rebuild your code for changes.  We recommend that you add all your client bundle specific dependencies to the Vendor DLL configuration (within /config).
==> VENDORDLL -> Vendor DLL build complete. The following dependencies have been included:
    -react
    -react-async-component
    -react-dom
    -react-helmet
    -react-router-dom

==> Creating a development bundle configuration for the "client"
webpack building...
==> CLIENT -> Building new bundle...
webpack built 25a494fb3ac95427d774 in 3506ms
==> CLIENT -> Running with latest changes.
==> Creating a development bundle configuration for the "server"
==> SERVER -> Building new bundle...
==> SERVER -> Server running with latest changes.
Server listening on port 1337

Anyways, my real question as about the Counter variable. Every time I switch to different different tabs like Home, About, the counter I incremented doesn't keep the value. It always reset it to zero. Is this a bug or this was intentional? I hope it kept the last value so people won't think there is an issue in the code. I really thought it was a bug.

birkir commented 7 years ago

Yes, for the sake of simplicity we don't ship a system-wide store for keeping state between components. You can see that the initial state is set in the constructor of the counter route.

You will want to use something like mobx or redux to keep the state.

c0debreaker commented 7 years ago

Thank you.