Is that this a “nested perform name” to a hook?




That is the rule of calling hooks:

Don’t name Hooks inside loops, circumstances, or nested capabilities. As an alternative, all the time use Hooks on the high degree of your React perform, earlier than any early returns.

For the utilization in HOC like beneath taken from https://github.com/launchdarkly/react-client-sdk/blob/e2f79f1c156e5e82f70cd88fd2bf22dc3be8ecad/src/withLDConsumer.tsx#L43:

perform withLDConsumer(choices: ConsumerOptions = { clientOnly: false }) {
  return perform withLDConsumerHoc<P>(WrappedComponent: React.ComponentType<P & LDProps>) {
    return (props: P) => (
      <Shopper>
        {({ flags, ldClient }: LDContext) => {
          if (choices.clientOnly) {
            return <WrappedComponent ldClient={ldClient} {...props} />;
          }

          return <WrappedComponent flags={flags} ldClient={ldClient} {...props} />;
        }}
      </Shopper>
    );
  };
}

Enter fullscreen mode

Exit fullscreen mode

Can I take advantage of hooks within the returned nameless perform, like beneath?

perform withLDConsumer(choices: ConsumerOptions = { clientOnly: false }) {
  return perform withLDConsumerHoc<P>(WrappedComponent: React.ComponentType<P & LDProps>) {
    return (props: P) => (
      const [name, setName] = useState('Mary'); 
      <Shopper>
        {({ flags, ldClient }: LDContext) => {
          if (choices.clientOnly) {
            return <WrappedComponent ldClient={ldClient} {...props} />;
          }

          return <WrappedComponent flags={flags} ldClient={ldClient} {...props} />;
        }}
      </Shopper>
    );
  };
}
Enter fullscreen mode

Exit fullscreen mode

I feel it’s a “all the time use Hooks on the high degree of your React perform”, however my good friend mentioned it’s a “nested perform”. My understanding to that is that this “nest” ought to solely rely from the perform part degree.



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout extra Articles on Sayed.CYou

#nested #perform #name #hook