I would like to propose a feature to be implemented in react based on this library https://github.com/myckhel/react-use-component
The react-use-component was created to limit the use of memoised callback hooks and to create Object Oriented functional Components.
I would like the react team to look into the concept of this API and consider its benefits to the amazing React framework.
Thanks for your review.
Might as well use React extends Components if someone has to use this approach. What benefit do you think this approach will give?
Most of us are not using React Class Component because we want to make use of React Hooks by using functional components.
Since i prefer using functional components
This approach will give me:
useCallback, useMemo since you you can pass prop variables to child components by reference rather than valueI don't see the benefit of that hook over
const self = useMemo(() => someObj, [])
nor
const self = useRef();
if (!self.current) {
self.current = someObj;
}
nor does it become an out-of-the-box hook
I don't see the benefit of that hook over
const self = useMemo(() => someObj, [])nor
const self = useRef(); if (!self.current) { self.current = someObj; }nor does it become an out-of-the-box hook
I haven't written any code in the way you have commented.
Well i think i didn't explain it as clearer as possible
but i believe some people will understand what im trying to propose.
I will try to create a code sandbox so that we all can experiment with it and understand the proposal.
I have created a codesandbox app for the use case: https://codesandbox.io/s/react-usecomponent-example-67t3v
As I see it, useComponent is an anti-pattern for the one of the core goals of hooks: logic composition.
It seems the proposal is to have a hook similar to the React class component model.
The purpose of the hooks was to solve these problems.
- It鈥檚 hard to reuse stateful logic between components
- Complex components become hard to understand
https://reactjs.org/docs/hooks-intro.html#its-hard-to-reuse-stateful-logic-between-components
- Huge components that are hard to refactor and test.
- Duplicated logic between different components and lifecycle methods.
- Complex patterns like render props and higher-order components.
We think Hooks are our best shot at solving all of these problems. Hooks let us organize the logic inside a component into reusable isolated units:
https://dev.to/dan_abramov/making-sense-of-react-hooks-2eib
The useComponent proposal does not seem to fit the problem the hooks was intended to solve.