question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: useComponent Hook

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
myckhelcommented, Nov 22, 2020

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:

  • ability to make my functional components object Oriented as if im using a Class Component

  • ability to not use useCallback, useMemo since you you can pass prop variables to child components by reference rather than value

5reactions
kunukncommented, Nov 27, 2020

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’s 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks at a Glance - React
Hooks are functions that let you “hook into” React state and lifecycle features from function components. Hooks don't work inside classes — they...
Read more >
Lifecycle hooks - Angular
Your application can use lifecycle hook methods to tap into key events in the lifecycle of a component or ... Use component and...
Read more >
A Simple Explanation of React.useEffect() - Dmitri Pavlutin
useEffect() hook executes side-effects in React components. ... Examples of side-effects are fetch requests, manipulating DOM directly, ...
Read more >
How to use componentWillMount() in React Hooks?
And with Hooks you can only use in functional components. The line below comes from ... Network requests can be done in componentDidMount....
Read more >
From class components to React Hooks - CircleCI
Writing and automating tests for React Hooks. Starting with version 16.8, React provides a way to use component and global state without the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found