Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1.48 KB

README.md

File metadata and controls

37 lines (27 loc) · 1.48 KB

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);