I
I
Ilya2019-04-20 15:35:24
React Native
Ilya, 2019-04-20 15:35:24

How to pass a value to state from another page?

For routing I use react-navigation.
There are two pages:
HomePage (main page).
HomePageList(main page only all items in list view) What I
need to do is:
When I click on an item from the list on the HomePageList page. Should pass the value in state to the HomePage.
Let's say I click on item 12 on the HomePageList page.
On HomePage, 12 should be passed to state activeSlide.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Alexandrovich, 2019-04-23
@ynizhenie

async ActiveSlide() {
    let value = await this.props.navigation.getParam("index");
    if (value !== undefined) {
     await  this.setState({  //вот тут изменения 
        activeSlide: value
      });
      this.props.navigation.state.params.index = undefined;
    }
  }

N
Nick, 2019-04-22
@DragonSpirit

The second parameter of the navigate function allows you to pass an object with parameters. More details with a code example can be found in the official documentation .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question