I think NextJS lead reactjs to a doom way
Finally I maintained a nextjs based project.
Yes, I know they create Server Component/Server-Side Render
But, everywhere are server components, it means, you can't use useState, useEffect and such client-function at all.
It means, nextjs turns the SPA to refresh page.
It means, you can't use console.log() or debugger; easily in a component, otherwise you have to turn the component into a client-component.
A lot of nextjs pages call async/await request, do they optimized these actions, combined many request into one? I don't know, but I don't feel pages loaded quicker than before.
And when I counter a real situation: * props.dataSource pass into
* component(use client), processed props.dataSource (React.useState(data.slice(0, defaultShowItems)))
* props.dataSource updated
* useState() return an old value
I have to give the component a fresh new key every time to fix this problem.
That's awkward, I heard motto, nextjs re-invent PHP, now I really feel it.
16 comments
[ 560 ms ] story [ 695 ms ] threadYou can pass client components to server components, and have access to hooks & effects. See
- https://nextjs.org/docs/app/building-your-application/render...
- https://nextjs.org/docs/app/building-your-application/render...
You are also not required to use server components with NextJS and you can use it as a better overall DX and simplifications like directory (convention) based routing
How do you see React "moving away"? Maybe you mean React should not have gone down the server component path?
But from that real situation with props.dataSource, I would not expect the state from that useState to return a new value on prop update, even in a normal react app / without next. If you are not setting this client state (with the second method destructed from the hook) you could potentially ditch the useState completely and just run that data.slice(0, defaultShowItems) as is in the function body, or wrap in memo if calculation is expensive.
This is the best way to introduce it. Vercel makes it too complicated in the docs where everything is splitted into app/pages, creating a large ecosystem gap.
And only if you are a experienced developer, new comers never know how to solve this.
I think RSC has great potential, but Nextjs conventions limit its potential to the fullest.