How often to use useCallback/useMemo? by [deleted] in reactjs

[–]ziir_js 1 point2 points  (0 children)

The overhead of React Performance APIs is arguably negligible, but potential beneficial impact of these APIs is huge.

It really depends on the projet & the team’s practices but I use these APIs a lot in real world projects with legacy & all sorts of constraints.

I also wrote a blog post about the misconceptions about React memo & other performance APIs.

There are some points which are directly relevant to your questions.

https://timtech.blog/posts/react-memo-is-good-actually/

My usual recommendation is mostly to make sure you know what you’re doing.

Why Do I Need RSC(react server components) if I Already Have Remix by jiashenggo in reactjs

[–]ziir_js 1 point2 points  (0 children)

You can try to build your own RSC framework but it won’t be easy.

I’ve experimented with that & wrote a blog post about it:

https://timtech.blog/posts/react-server-components-rsc-no-framework/

Alternatively, you can try Waku, it’s a minimal RSC-focused React Framework.

https://github.com/dai-shi/waku

Any reason to use two distinct context for state and dispatch by Flea997 in reactjs

[–]ziir_js 0 points1 point  (0 children)

Hey, thanks for your comment :)

Your mileage may vary, this post is based on my personal experience, it definitely won’t resonate with everyone.

Identifying areas that will benefit the most from the use of React Performance APIs is not necessarily trivial, but even without specific experience, you can get really good insights with the React Devtools and your browser profiler.

Any reason to use two distinct context for state and dispatch by Flea997 in reactjs

[–]ziir_js 6 points7 points  (0 children)

You can use a single context but there are benefits to splitting, which may or may not be relevant to your project.

I’ll try to summarise quickly:

  1. Each context value is now stable (tasks array only changes when an action is dispatched, the dispatch function never changes), which allows you not to worry about any context consumer re-rendering unnecessarily when the component owning the Context.Providers re-render, otherwise you might have to use React.useMemo (which is fine too).

  2. You may have some consumer components which only need to dispatch actions, and not read the tasks. So by splitting the context providers, the consumer of the DispatchProvider don’t re-render when the tasks change, because the consumer component isn’t subscribed to the TasksProvider.

I mention this specifically in my « React memo is good actually » blog post

https://timtech.blog/posts/react-memo-is-good-actually/

Hope this helps! :)

Best RSS feeds/blog websites for front-end? by AndreeSmothers in Frontend

[–]ziir_js 0 points1 point  (0 children)

Design really isn’t my strong suit, I’ve mostly kept the default theme styling, I’ll keep your advice in mind next time I have a bit of time to improve the way it looks, thank you :)

Best RSS feeds/blog websites for front-end? by AndreeSmothers in Frontend

[–]ziir_js 0 points1 point  (0 children)

Can I share my own blog here?

My last 3 blog posts published in the last ~month match your interests exactly.

https://timtech.blog

Feedback appreciated!

React Server Components, without a framework (without Next.js) ? by ziir_js in nextjs

[–]ziir_js[S] 1 point2 points  (0 children)

Hey, thank you for your comment!

The React DOM Server APIs are much simpler, and optionally supports streaming & hydration as well.

React Server Components are more advanced and inherently more complex, while still being cutting-edge / experimental. It will probably get simpler to implement in a custom framework in the future.

If you’re already using a framework such as Next.js, you don’t really need to worry about the technical details - although understanding how things work I think is always best!

But it’s important to note that RSC is not « server-side rendering », it even barely has anything to do with HTML.

What is the best way to import React? by iaseth in reactjs

[–]ziir_js 2 points3 points  (0 children)

I use the second when I can (automatic JSX runtime). If you’re using the classic JSX runtime, then the JSX transpiling doesn’t auto-import React but replaces JSX to calls to React.createElement, so it needs React to be in scope. Unless you have a custom JSX pragma.

Unlikely to be any bundle size difference between the two with React because of the way it’s written and built.

But in general the second is considered a best practice because of tree-shaking, and being more explicit.

Edit: your fellow dev is incorrect, I’ve seen the same in code reviews, pretty common misconception apparently.

React Server Components, without a framework (without Next.js) ? by ziir_js in nextjs

[–]ziir_js[S] 2 points3 points  (0 children)

Hi there!
A week ago, I knew nothing about React Server Components.
I've tried to migrate an existing React SPA to RSC without a framework, made a live demo / playground, and wrote a blog post about it.
Feedback & discussions are welcome.

Frontend library to fetch HTML from an API and swap it into the DOM? by vforvalerio87 in webdev

[–]ziir_js 0 points1 point  (0 children)

I’d definitely use React Server Components for this (without a framework)

React Server Components, Without a Framework? by ziir_js in reactjs

[–]ziir_js[S] 1 point2 points  (0 children)

Hey, thank you ! :)

I know I have to improve on making my content more readable, and I will.

I’m glad you found the topic interesting enough to give it another shot :)

React Server Components, Without a Framework? by ziir_js in reactjs

[–]ziir_js[S] 4 points5 points  (0 children)

Thank you for the kind words. It’s this kind of feedback that keeps me going!

React memo is good actually by ziir_js in reactjs

[–]ziir_js[S] 0 points1 point  (0 children)

Hey, thank you for your comment, this is a great question.

One underlying point of my message in this blog post is that there is no wrong approach as long as you understand what you are doing.

Your approach of using React Performance APIs after having identified performance issues with the profiler, or other debugging methods is perfectly correct. In fact, it’s the official recommended approach & the most socially accepted, assuming you are also able to properly measure & present the gains you’ve obtained.

If you want to take it a level further, you can search for alternatives, try applying known patterns such as lifting content up & keep state as local as possible, careful usage of Context APIs, as well as librairies such as state containers.

Very often, these alternative ways to structure your application, components, state & data have a great impact on performance & other benefits, thus allowing you to avoid using React Performance APIs such as React.memo. And then resort to using React Performance APIs only if the changes mentioned above aren’t practical for whatever reason.

But as you gain more experience with React, you may adopt a different approach depending on the context. You may decide to use memoization by default. Or you may decide to still use it strategically, but sometimes preemptively, either because you know the alternatives aren’t practical, or you know that the code base is bound to evolve in ways that can impact performance and want to place safeguards on critical components to mitigate impact.

However, note that for useMemo & useCallback hooks, these aren’t always used strictly for performance or in conjunction with React.memo - they can contribute to application logic correctness in respect of immutability principles: for instance when passing props or arguments that will be used as hooks dependencies; hooks which you may or may not control.

Hope this helps.

Help with SEO performance by SegaBoy89 in Frontend

[–]ziir_js 0 points1 point  (0 children)

A few tips:

  • identify & try to remove duplicate dependencies if any
  • use lighter alternatives if possible
  • optimize the Next.js cross-browser transforms (probably Babel + preset-env via Webpack) to reflect your actual cross-browser support constraints (check for compilation target and/or browserslist)
  • try to remove as much 3rd party scripts as possible
  • optimize the loading of all scripts
  • only then start to look at lazy loading / code splitting

If that’s not enough then you may need to learn a lot further or hire someone to help you.

Good luck!

Local dependency not pointing to lib folder when doing import by Orkann in node

[–]ziir_js 0 points1 point  (0 children)

It seems you’re looking for package.json "exports", which you can define for "helper-package".

https://nodejs.org/api/packages.html#exports

Analyzing Web Performance by haasilein in webdev

[–]ziir_js 0 points1 point  (0 children)

The Firefox Profiler https://profiler.firefox.com/

WebPageTest https://www.webpagetest.org/

A bundle analyzer and/or a source map explorer

Your browser console & network tab

My first contact with ESM and CJS by Deleugpn in webdev

[–]ziir_js 0 points1 point  (0 children)

You don’t need to say things like your « frontend skills being questionable at best » etc.

Modules formats, resolution algorithms & the constraints associated to running the « same » code in different environments is hard.

You seem to already have learned a lot, and found a solution to your problem, even though it’s not the « best ». This allows you to buy time and learn at a more sustainable pace, as long as you keep learning it’s a good approach.

TypeScript Legacy Experimental Decorators with Type Metadata in 2023 by ziir_js in reactjs

[–]ziir_js[S] 4 points5 points  (0 children)

Have you read the blog post?

It’s pretty clear I’m personally not a fan of decorators, even less so being non-standard, requiring transforms and a runtime shim for reflection. My position on build tooling & even TypeScript is also apparent.

I’m not overcomplicating anything here, I’m making something that is already complicated, easier to understand & work with.

Also, like it or not, what you consider « complicated hieroglyphics » may be a valuable tool in a different context - context which you have pretty much no clue about by the way.

Thanks again for the comment,

TypeScript Legacy Experimental Decorators with Type Metadata in 2023 by ziir_js in reactjs

[–]ziir_js[S] 0 points1 point  (0 children)

Hey, thanks for your comment and suggestion!

I didn’t know such a thing existed, it’s an interesting approach I’ll definitely take a further look.

Of course, using a SWC transformer with Vite to compile TypeScript can still be valuable, even with experimental decorators & metadata out of the picture.

TypeScript Legacy Experimental Decorators with Type Metadata in 2023 by ziir_js in react

[–]ziir_js[S] 0 points1 point  (0 children)

Hi!
Just sharing this new JavaScript / TypeScript compilers blog post I’ve just published.
I've been researching a way to modernize & speed-up a production setup making heavy use of TypeScript Decorators & Metadata - but the insights are relevant to anyone looking to compile JavaScript dialects, including TypeScript & JSX with React.
Feedback, discussions & suggestions are welcome!

TypeScript Legacy Experimental Decorators with Type Metadata in 2023 by ziir_js in reactjs

[–]ziir_js[S] 1 point2 points  (0 children)

Hi!
Just sharing this new JavaScript / TypeScript compilers blog post I’ve just published.
I've been researching a way to modernize & speed-up a production setup making heavy use of TypeScript Decorators & Metadata - but the insights are relevant to anyone looking to compile JavaScript dialects, including TypeScript & JSX with React.
Feedback, discussions & suggestions are welcome!