How do you type a React component's props?
Simple meaning
I define a Props interface and annotate the function parameter.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Frontend Master questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
I define a Props interface and annotate the function parameter.
Open the full page for Why, Steps, Example and Key takeaway.
Any turns off checking, so I can access any property and hide bugs.
Open the full page for Why, Steps, Example and Key takeaway.
I model idle, loading, success with data, and error with a message as a discriminated union.
Open the full page for Why, Steps, Example and Key takeaway.
It tells you when an element enters the viewport without scroll listeners.
Open the full page for Why, Steps, Example and Key takeaway.
PushState and replaceState change the URL without a full reload, which SPAs use for routing.
Open the full page for Why, Steps, Example and Key takeaway.
All fails fast if any promise rejects, which is good when every request is required.
Open the full page for Why, Steps, Example and Key takeaway.
The question mark dot stops the lookup and returns undefined if the left side is null or undefined.
Open the full page for Why, Steps, Example and Key takeaway.
Document.cookie can set cookies the page can also read, so XSS can steal them.
Open the full page for Why, Steps, Example and Key takeaway.
If I add a window resize listener in useEffect and forget the cleanup, the handler keeps the component closure alive after unmount.
Open the full page for Why, Steps, Example and Key takeaway.
A generic is a type parameter so a function or component works with many shapes while keeping the relationship.
Open the full page for Why, Steps, Example and Key takeaway.
Slice returns a shallow copy of a portion and does not change the original, which is what I want in React.
Open the full page for Why, Steps, Example and Key takeaway.
The effect starts after paint, fetch is scheduled, and the function yields at await so React can keep working.
Open the full page for Why, Steps, Example and Key takeaway.
I reproduce by changing filters quickly and logging request ids.
Open the full page for Why, Steps, Example and Key takeaway.
I use a status field like idle, loading, success, error and narrow with a switch.
Open the full page for Why, Steps, Example and Key takeaway.
Interfaces with the same name in the same scope merge their members, which is useful for extending libraries.
Open the full page for Why, Steps, Example and Key takeaway.
When fetch uses credentials include, the server cannot reply Access-Control-Allow-Origin star.
Open the full page for Why, Steps, Example and Key takeaway.
They can serve shell HTML and assets offline, which is great for PWAs.
Open the full page for Why, Steps, Example and Key takeaway.
Synchronous logs run first.
Open the full page for Why, Steps, Example and Key takeaway.
Class Foo still has Foo.prototype and instances link to it.
Open the full page for Why, Steps, Example and Key takeaway.
In the effect I create a controller, pass signal to fetch, and abort in cleanup.
Open the full page for Why, Steps, Example and Key takeaway.