Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot easily use in react class #21

Closed
kbrown opened this issue Jun 25, 2019 · 2 comments
Closed

Cannot easily use in react class #21

kbrown opened this issue Jun 25, 2019 · 2 comments

Comments

@kbrown
Copy link

kbrown commented Jun 25, 2019

I'd like to use this library without converting all of my react classes to functional components. Hooks must be called from React function components, or from custom hooks.

So it would be nice to be able to use the HOC way:

function withCollapse(Component) {
  return function WrappedComponent(props) {
    const collapseProps = useCollapse({});
    return <Component {...props}  {...collapseProps} />;
  }
}
@roginfarrer
Copy link
Owner

How about this?

function Collapse(props) {
  const collapseProps = useCollapse(props);
  return props.children(collapseProps);
}

https://codesandbox.io/s/usecollapse-as-a-render-component-67tnd

You can make a component that uses the render prop API. It's props become the initial config, and you don't need to use a hook.

@roginfarrer
Copy link
Owner

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants