Re:React Docs Beta – rewritten with hooks and interactive ex...
by anarchy8 on Saturday October 23, 2021 @02:04PM
(#28970834)
It really should have Typescript as well (optionally, that is)
[ Parent
| on HN ]
Re:React Docs Beta – rewritten with hooks and interactive ex...
by kall on Saturday October 23, 2021 @03:22PM
(#28971406)
I think the way the docs introduce functional components (destructure the props argument right away) sets you up for success with TypeScript. The main ways to get started that they recommend (CodeSandbox, CRA, next.js) let you add typescript down the line with no hassle, so you don't loose out by starting without it. Seems better to teach people one thing at a time. React with TypeScript really doesn't look all that different and if you just drop what they teach you into an existing TS project, it will work ok.
An official "Using React with Typescript" doc that shows good patterns for typing props and state would be nice though.
Re:React Docs Beta – rewritten with hooks and interactive ex...
by acemarke on Saturday October 23, 2021 @03:55PM
(#28971684)
The de-facto standard resource on React + TS is the community-maintained React TypeScript Cheatsheet site:
https://react-typescript-cheatsheet.netlify.app/
But yes, I'd love to have some of this info added to the official docs as well.
Re:React Docs Beta – rewritten with hooks and interactive ex...
by danabramov on Saturday October 23, 2021 @04:16PM
(#28971843)
Yeah we’d like to add something (potentially even toggles) but out of scope for the first iteration.
Re:React Docs Beta – rewritten with hooks and interactive ex...
by acemarke on Saturday October 23, 2021 @04:19PM
(#28971861)
Sweet!
As an FYI for later reference, Lenz Weber has a Remark plugin that compiles TS to JS in code samples - we use that in the Redux Toolkit docs. I think Orta Therox may have something similar going on with his "Shiki Twoslash" tooling, but not entirely sure.
Re:React Docs Beta – rewritten with hooks and interactive ex...
by _fat_santa on Saturday October 23, 2021 @06:28PM
(#28972992)
That would be amazing. I would love it if they put together a guide to proper typechecking around hooks.
Re:React Docs Beta – rewritten with hooks and interactive ex...
by TameAntelope on Saturday October 23, 2021 @04:29PM
(#28971939)
Well, this is Typescript, isn't it?