Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Icon] Internal React error: Expected static flag was missing #6267

Closed
ptgamr opened this issue Jul 10, 2023 · 1 comment · Fixed by #6268
Closed

[Icon] Internal React error: Expected static flag was missing #6267

ptgamr opened this issue Jul 10, 2023 · 1 comment · Fixed by #6268

Comments

@ptgamr
Copy link

ptgamr commented Jul 10, 2023

Environment

  • Package version(s): 5.0.0
  • Operating System: All
  • Browser name and version: All

Code Sandbox

N/A

Steps to reproduce

Render an Icon component

Actual behavior

2023-07-10-211204_1025x314_scrot

Expected behavior

That error / warning should not be appearing, it doesn't break anything, but having the error during development is quite annoying

Possible solution

Looks like the icon component has a conditional return before usage of hooks. And it is not recommended, as per hook rules, or this comment facebook/react#24391 (comment)

I think the part after the return can be extracted to a private component, something like:

export const Icon: React.FC<IconProps> = React.forwardRef<any, IconProps>((props, ref) => {
    const { icon } = props;
    if (icon == null || typeof icon === "boolean") {
        return null;
    } else if (typeof icon !== "string") {
        return icon;
    }
    
    return <IconInner {...props} />
}

// and then the rest of the code can go into the `<IconInner>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants