{"id":16597232,"url":"https://github.com/adrianmcli/test-next","last_synced_at":"2025-03-06T19:32:37.776Z","repository":{"id":73736887,"uuid":"81704459","full_name":"adrianmcli/test-next","owner":"adrianmcli","description":null,"archived":false,"fork":false,"pushed_at":"2017-02-13T03:36:16.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-17T04:44:18.591Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrianmcli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-12T05:10:18.000Z","updated_at":"2017-02-12T05:10:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff57913a-d5c8-4843-8f4e-6da2868bf7fb","html_url":"https://github.com/adrianmcli/test-next","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmcli%2Ftest-next","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmcli%2Ftest-next/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmcli%2Ftest-next/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmcli%2Ftest-next/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrianmcli","download_url":"https://codeload.github.com/adrianmcli/test-next/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242274644,"owners_count":20101082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T23:55:17.248Z","updated_at":"2025-03-06T19:32:37.754Z","avatar_url":"https://github.com/adrianmcli.png","language":"JavaScript","readme":"\n# Redux example\n\n## How to use\n\nDownload the example [or clone the repo](https://github.com/zeit/next.js):\n\n```bash\ncurl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-redux\ncd with-redux\n```\n\nInstall it and run:\n\n```bash\nnpm install\nnpm run dev\n```\n\nDeploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))\n\n```bash\nnow\n```\n\n## The idea behind the example\n\nUsually splitting your app state into `pages` feels natural but sometimes you'll want to have global state for your app. This is an example on how you can use redux that also works with our universal rendering approach. This is just a way you can do it but it's not the only one.\n\nIn this example we are going to display a digital clock that updates every second. The first render is happening in the server and then the browser will take over. To illustrate this, the server rendered clock will have a different background color than the client one.\n\n![](http://i.imgur.com/JCxtWSj.gif)\n\nOur page is located at `pages/index.js` so it will map the route `/`. To get the initial data for rendering we are implementing the static method `getInitialProps`, initializing the redux store and dispatching the required actions until we are ready to return the initial state to be rendered. The root component for the render method is the `react-redux Provider` that allows us to send the store down to children components so they can access to the state when required.\n\nTo pass the initial state from the server to the client we pass it as a prop called `initialState` so then it's available when the client takes over.\n\nThe trick here for supporting universal redux is to separate the cases for the client and the server. When we are on the server we want to create a new store every time, otherwise different users data will be mixed up. If we are in the client we want to use always the same store. That's what we accomplish on `store.js`\n\nThe clock, under `components/Clock.js`, has access to the state using the `connect` function from `react-redux`. In this case Clock is a direct child from the page but it could be deep down the render tree.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianmcli%2Ftest-next","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrianmcli%2Ftest-next","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianmcli%2Ftest-next/lists"}