Use React hooks with your class components by Higher Order Component.
This is intended to help incrementally transition large existing class components to hooks. Please write new components using functions!
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);