1

I am using react native. Here's my code.

function mapStateToProps(state) {
  return {
    markers: state.markers,
  };
}

I set props using mapStateToProps and it only called when I dispatch an action. I can set state using setState({..}); like this.

Here's my question. How can I set props? Is there anything like setProps({..})?

13
  • Set props for what? mapStateToProps allows you to select state from the redux store and injects that state into your component Commented Oct 4, 2017 at 14:08
  • Show us your reducer that handles the markers state and if you've made any actions for it. Commented Oct 4, 2017 at 14:09
  • Yeah, right. But is there anyway to change props without using redux? Commented Oct 4, 2017 at 14:10
  • My actions and redux works well. But I want to set my props manually without using redux. Commented Oct 4, 2017 at 14:11
  • 3
    Sorry i don't understand your question and what you're trying to do Commented Oct 4, 2017 at 14:23

2 Answers 2

1

It seems like you're using Redux. If you do, make sure to have both reducer and action scripts. The reducer is used to get a value from a specific state property or properties.

You have to define a function in your action script to assign or set a value to your specific state property and properties. You also need a store to bring both reducers and actions together.

The store initializes everything and allows you to dispatch actions and set or get values.

Sign up to request clarification or add additional context in comments.

Comments

1

Two common ways of passing the props.

  1. From Redux Store Like what you have done in your code.

  2. From other Components Props can be passed by

<Foo prop1={bar} />

And in your Foo Component the props of prop1 is whatever bar is.

1 Comment

Is there anyway to change props byself in component?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.