Replies: 9 comments 4 replies
-
You should use |
Beta Was this translation helpful? Give feedback.
-
My main problem is, the client is working perfectly. I have no problem using the redux store with the client. But I need to be able to render the content in the store to the server side when a user first visits. |
Beta Was this translation helpful? Give feedback.
-
You probably misunderstood here. next-redux-wrapper doc doesn't mention anywhere about syncing client state to server. Moreover, when client gets more data from server, the state from server has to be manually merged with existing client state. |
Beta Was this translation helpful? Give feedback.
-
But isn't one of the mayor reasons to use Next.js to get server rendered HTML apps, which helps with SEO and such? I am able to manually render server side with getServerSideProps(). if I fetch the data inside of the function, and return it as props. When I render the props in JSX, its visible in the HTML source code as well. But that's bypassing the redux store. I am also able to use a redux store and render everything client side, vanilla react style, but that's not visible in the HTML source code. When a user visits the page, (or refresh the page) the server needs to generate some data to show the user. On a client side UI, I can just pull the stuff from the API with the help of my redux thunk action function, pass it to the reducer, which makes it available in the redux store. I can then use useSelector, and pull out the data I want. I need to be able to render that initial API fetch as server side HTML, so that it will be available when for example the Google-bot visits my app. In this case, having server rendered HTML for the bot is very important. The rest of the user-session can be client-side, but it needs to be able to fall back on that initial state, which is data fetched from an API, whenever a user enters or refreshes the page. I've looked at the clock and counter examples, but I'm not able to turn it into something usable. No matter what I do, I always end up rendering it client side instead of server side. How can I render it server side? |
Beta Was this translation helpful? Give feedback.
-
Even i got into the same issue of trying to use Redux store on Initial render and it does not work, I can make use of getStaticProps, but that is like bypassing redux and creating all logic of redux into getStaticProps which I don't want. I wanted to dispatch a redux action before the static HTML is built and pass the store to the component |
Beta Was this translation helpful? Give feedback.
-
Hi, I don't know if it can help you, but I am doing redux actions from getServerSideProps My _apps.js:
Example of page :
for more readability in my component, my action is separate :
and the last stage of my construction is in store.js
my approach may not be the best but it works :) if you have any feedback don't hesitate |
Beta Was this translation helpful? Give feedback.
-
@Devalo did you solve it? |
Beta Was this translation helpful? Give feedback.
-
can it for next 13.5? |
Beta Was this translation helpful? Give feedback.
-
I am using server side store and the same is being hydrated to the client side, the problem is we have to create a new store on each request, and its being retained by the server resulting in the server side memory leak. Anyone has any idea about that? |
Beta Was this translation helpful? Give feedback.
-
I've been working on a problem for a couple of days. It's probably because I don't fully understand how it's supposed to work. I've tried googling but it doesn't seem like the answer is anywhere to be found. I'm using redux, redux-thunk and next-redux-wrapper. I'm choosing to use next-redux-wrapper because it should make it easy to synchronize the client and server.
All the entries are in the redux store. I need them to be available server side on the first request. I need to figure how to put the returned data from the reducer to the server as well. Or am I thinking about this all wrong? I am new to Next.js, though I know my way around a vanilla React.js app.
I've based most of the code on the official example https://github.com/vercel/next.js/tree/canary/examples/with-redux-wrapper
And the official next-redux-wrapper example https://codesandbox.io/s/next-redux-wrapper-demo-7n2t5?file=/static.tsx
If I'm using getStaticProps or getServerSideProps makes no difference. I get the same output.
I'm really hoping anyone understands my problem, and are able to help me. It doesn't seem like I'm able go get any further as is. I was pretty impressed with Next.js and the server side rendering. This seems like a perfect way of using react within a framework.
I need the SEO. I either need to drop Next.js all together, or find another way to manage state, if this doesn't work. (but i'm sure there is an intuitive way, regarding how many big apps that are made with this framework :) )
If you take your time to have a look at this, Thanks!
Stephan Valois
index.js
Reducer with action
getAll from exampleService. This is irrelevant to the problem, but I'm adding it anyway so you can read the whole program.
_app.js This is taken directly from the official example
store.js This is taken directly from the examples. It's kind of a mix between both, since I've tried multiple things to get it to work. I must say, it doesn't work with the pure examples either.
Beta Was this translation helpful? Give feedback.
All reactions