Skip to content

Use React hooks with your class components

License

Notifications You must be signed in to change notification settings

melissafzhang/hook-hoc

 
 

Repository files navigation

Hook HOC

CircleCI Coverage Status npm downloads gzip size npm version PRs Welcome

Use React hooks with your class components by Higher Order Component.

Warning:

This is intended to help incrementally transition large existing class components to hooks. Please write new components using functions!

Example

import withHook from 'hook-hoc';
import { useResource } from 'rest-hooks';

import UserResource from 'resources/user';

const useProfile = ({ id }: { id: number }) => {
  const user = useResource(UserResource.detailShape(), { id });
  const friends = useResource(UserResource.listShape(), { id });
  return { user, friends };
}

class Profile extends React.PureComponent<{ id: number, user: UserResource, friends: UserResource[] }> {
  //...
}

export default withHook(useProfile)(Profile);

About

Use React hooks with your class components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 43.5%
  • TypeScript 30.5%
  • HTML 26.0%