Bob Dylan Bob Dylan - 1 month ago 7
React JSX Question

Can i send full store object from container to action creator (React/Redux)

Guys i don`t fully understand if this correct solution, but can i send some specific store Array[Object] from container to Action creator?

Task is to implement search in store.

Example of action creator

export const mySearch = (search) => {
return {
type: SEARCH,
a: data.text, //some additional value
b: data.items //store object
}

Ole Ole
Answer

You could apply some data from your store to the properties of your component.

const mapeStateToProps = state => ({ data: state.data });

From there you create your action by a "higher order function", passing your property in.

const mapDispatchToProps = dispatch => {
  const mySearch = data => search => dispatch({
    type: SEARCH,
    a: data.text,
    b: data.items,
  });

  return { mySearch };
};

Now call it from your component.

const Component = props =>
  <input type="search" onUpdate={props.mySearch(props.data)} />;

You can get the value of the input by your search parameter: search.target.value

Comments