Back to Clerk

`withUser` function removed

packages/upgrade/src/versions/core-2/common/withuser-hof-removed.md

latest697 B
Original Source

The withUser higher order function has been removed. If you would still like to use this function in the way its implemented, it can be created quickly using Clerk's custom hooks. An example of how to do so is below:

js
function withUser(Component, displayName) {
  displayName = displayName || Component.displayName || Component.name || 'Component';
  Component.displayName = displayName;
  const HOC = props => {
    const clerk = useUserContext();

    if (!user) return null;

    return (
      <Component
        {...props}
        user={user}
      />
    );
  };

  HOC.displayName = `withUser(${displayName})`;
  return HOC;
}