M
M
mix-92019-04-21 21:36:28
React
mix-9, 2019-04-21 21:36:28

How to change the react native state outside the component?

Good day. There is a component, when clicked, a simple request to the server occurs.
Something like this
(React native, redux)

class MasterScreen extends Component {
render() {
    return (<Button title={getPhrase('checkin')} onPress={() => this.onClick()} />);
}
....
onClick() {
      if(this.validate()) {
    sendRequest(this.data).then(result => { 
                   this.props.someAction(this.data.id);   // тут меняется state (redux)
.....

but from an architectural point of view, this is not very good. It is worth taking the logic out of the component. And here is the problem: how to change the state not from the component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-21
@mix-9

You can use redux-thunk
See answer for example logic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question