How to remove warning in React native

If you need to pass a non-serializable props, such as a function, then you can do this instead:

<Stack.Screen name="Home">
  {props => <PharmacyHome catId={this.props.navigation.state.params} {...props} />
</Stack.Screen>

I made it work by passing what I wanted through params instead of props. For you, it would look like this:

<Tab.Screen
    name="Home"
    component={PharmacyHome}
    initialParams={{ catId: this.props.navigation.state.params }}
/>

Hope this helps


The other answers do the job but these solutions have severe performance issues if your screen has a lot of components, in my case I had a Flatlist with elements ever increasing on scrolling.

So I figured out a solution. You can use the property 'children' to pass an element type jsx like instead of the property 'component'.

I'm using react navigation 5.x

<Tab.Screen
    name="Home"
    children={() => <PharmacyHome catId={this.props.navigation.state.params}/>}
    .
    .
    .
/>

This had no performance issues compared to what I was getting when trying for other solutions.


Quick Solution

Move your component definition into a separate line of code

        component={props => (
          <PharmacyHome
            catId={this.props.navigation.state.params}
            {...props}
          />
        )}

Instead

const YourComponent = props => (
  <PharmacyHome catId={this.props.navigation.state.params} {...props} />
);

      <Tab.Screen
        name="Home"
        component={YourComponent}

Explanation

Components use reference identity to determine when to re-renders ... so by passing component-definition as a prop, you're forcing it to create a new-object as a component with each-render ... causing unnecessary-re-renders for Tab.Screen, and no-state will be preserved between renders for YourComponent