gray0531
TTCTheo's Typesafe Cult
•Created by gray0531 on 5/3/2023 in #questions
Any recommend open source react project?
I am trying to optimize the project of company.
It is like a CRUD based shopping web.
I do use tanstack query for data fetching, zustand as global data center,
react-hook-form and zod.
They did help.
But in some scenario, I am still wondering is there a better solution or not.
e.g: It always bothers me that, I have to define another data structure for form data (which is familiar with the BE data model).
and a proper way to response to the server side error , sometimes as a global alert, sometimes you need to show a new procedure for the user in the component
2 replies
TTCTheo's Typesafe Cult
•Created by gray0531 on 1/30/2023 in #questions
When will the react Component remount?
I hear React itself use Object.is to decide whether to reRender a component or not
How about remounted?
What does React check?
I give Object.is a try in the link, but it ends up "not this"
https://stackblitz.com/edit/react-ts-tuqhjk?file=App.tsx,index.html
4 replies
TTCTheo's Typesafe Cult
•Created by gray0531 on 1/11/2023 in #questions
Complex object interface
Sometimes I get an object CoolStuff from api.
It has two kinds.
I try using discriminated unions.
type CoolStuff =
{type: 1, goodshit: ...}|
{type: 2, badshit: ...}
And I have two Components for each of them.
I am so sure in component 1, the corresponding type will be 1.
I use react query to fetch the CoolStuff.
But I don't know how to cast it (or any other good way to make ts system happy)
20 replies
TTCTheo's Typesafe Cult
•Created by gray0531 on 11/3/2022 in #questions
Not sure about router change?
By using next for few month , I have a question: What magic happens when router change?
Instead of empty html and a main js,next give me a contentful html and that is why nextjs is good for seo.After hydration,the
page become reactive.
I was thinking that Nextjs's job is done.
Everything is just like SPA.
But by changing to another route,things are getting unfamiliar.
I got a json, Is it for hydration?Or just some props for the page?
I try to open page source in chrome, I did see new content of new page!! God what is happening.
6 replies
TTCTheo's Typesafe Cult
•Created by gray0531 on 10/18/2022 in #questions
Problems of using middleware
I need some router guard implementation in my nextjs app.
The official answer is middleware, which runs on the server.
It gives me a chance to write my logic in one place and no useless api call or render .
But this brings more latency.
If I want to solve this problem, I need to use edge function, which is supported by limited suppliers. My team use Google cloud function (sadly no supported edge)
Are you guys using the middleware for the router guard?
Which points attract you?
13 replies
TTCTheo's Typesafe Cult
•Created by gray0531 on 10/10/2022 in #questions
What does nextjs do after router changes?
I saw the theo's last video about under the hood of nextjs.
Realizing after the first html loaded and hydration is done, then everything is like SPA.
This is so clear before I change the route.
In my case, I use a state call isDesktop to render mobile/desktop version of a page which depends on media query(default is false when runs on node)
I use router.push to redirect the page.
When I use desktop, I see a prerender page (mobile version) show up then immediately turn into desktop version.
I just don't know why prerender page still show up, because SPA do not work in this way.
It looks like it redo the html load and hydrates(even though It just download js chunk),but when I open devtools performance panel, there is no second hydration(just another render)
Sorry for my poor english😂, and thank you for your patience
1 replies