4

So I have this screen that show product details, it works like a template because only the data coming navigation params changes, I am having the issue because there's no reload, it works fine when going back and mounting it again, that's not the case here since I have related products showing on that same screen, I'll need a way to be able to either reload the current route or update the state

I have checked with console.log nothing shows up on second click

constructor (props) {
  super(props)
  this.state = {
    product: this.props.route.params.product,
    id: this.props.route.params.product.id,
  }
}

To navigate to use to the route I use on both the screen itself or in another route

viewProduct = (product) => {
  this.props.navigation.navigate('SingleProduct', { product: product })
}

I have tried setState inside of both componentDidMount and UNSAFE_componentWillReceiveProps but the results only shows after an additional click

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Youssef
  • 565
  • 1
  • 5
  • 21

3 Answers3

3

You can use the following function to navigate from singleProduction screen to the same screen with the different params.

this.props.navigation.replace('SingleProduct', { product: product })
rashi jain
  • 474
  • 3
  • 9
1
navigation.setParams({
   query: 'someText',
});

Taken from react navigation docs

Aliaksei
  • 1,094
  • 11
  • 20
0

use the route.params?.product directly and mention change in useEffect array.

  useEffect(() => {

    return () => {
      // Clean up the subscription
      
    };
  // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [route.params?.product]);
prisar
  • 3,041
  • 2
  • 26
  • 27