13 ms·
How do you mean? Imo it's easier to organize as you can split up your logic into normal functions and custom hooks (which are also just functions). I also find
by codeptualize 4y ago
How do you mean? Imo it's easier to organize as you can split up your logic into normal functions and custom hooks (which are also just functions).
I also find functions much easier to read as there is no "this" and you can simply read them top to bottom for order of execution.
- dylanowen 4y agoSo I spent some more time reading through using HOCs in React and I think I'll have to give functional components more of a try. The specific example I was thinking of is https://github.com/graphql/graphiql/blob/50674292c55eadf0e61993ffbbc7a6983c608bf4/packages/graphiql-react/src/editor/response-editor.tsx#L37 https://github.com/graphql/graphiql/blob/50674292c55eadf0e61... but this component will probably always be complex because of the Codemirror interaction.
- codeptualize 4y agoNice! I think you might like it. Ah yeah, that does take a while to unpack. I think a lot of the complexity there is dealing with a non-react library and the dynamic import(s). Binding non-react libraries can be a bit rough. I do think it's a good example to show the big advantage of hooks, if you look at the use of the hook, super clean: https://github.com/graphql/graphiql/blob/50674292c55eadf0e61993ffbbc7a6983c608bf4/packages/graphiql-react/src/editor/components/response-editor.tsx#L9 https://github.com/graphql/graphiql/blob/50674292c55eadf0e61... Great way to contain complexity and make usage really clean and simple!