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

WARN Looks like you're passing an inline function for 'component' prop for the screen 'Home' (e.g. component={() => <SomeComponent />}). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour. #21

Open
sebastianjung opened this issue Apr 28, 2023 · 5 comments

Comments

@sebastianjung
Copy link

sebastianjung commented Apr 28, 2023

It seems that this piece of code:
return React.createElement(Stack.Screen, { key: name, name: name, component: C, options: Opts });
throws warnings in minified bundle.

Changing the code to the following, seems to resolve the issue.
return React.createElement(Stack.Screen, { key: name, name: name, options: Opts },(props) => <C {...props} />);

Any thoughts on this?

@kanzitelli
Copy link
Owner

Hi @sebastianjung! Thanks for reporting the issue.

That's interesting, I've never faced that before. Navio's code is highly memoised (so shouldn't have unnecessary re-renders) but the warning is linked to this line, however I couldn't find anything wrong. I will need some time to test that and understand why it's happened.

Can you provide the steps on how to get to that warning? And maybe some code snippet?

@sebastianjung
Copy link
Author

@kanzitelli
I've been using your rn-starter template.

When minifiying with npx expo start --dev-client --minify the warning occures.

That may be sufficient.

@kanzitelli
Copy link
Owner

Hey @sebastianjung. I couldn't reproduce the warning on my end following the steps you provided. However, I changed some code in Navio related to the warning but idk if that's a correct way.

// line 633
return <Stack.Screen key={name} name={name} component={C} options={Opts} />;

Changed to

return (
  <Stack.Screen key={name} name={name} options={Opts}>
    {(props: any) => <C {...props} />}
  </Stack.Screen>
);

And after building it, it generated following code:

return (React.createElement(Stack.Screen, { key: name, name: name, options: Opts }, (props) => React.createElement(C, { ...props })));

It seems the same with what you sent before. But I'm not sure if that's correct way of building react-navigation's Stack Screens component. Let me know if that resolves the issue.

@sebastianjung
Copy link
Author

@kanzitelli Sorry, but how to test if this works? Any branch i should check inside my project?

@sebastianjung
Copy link
Author

I tried cloning this repo but building it does not give me a dist folder (probably because no bundler is involved). Sorry, i am not sure how to properly build this project i guess.

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

No branches or pull requests

2 participants