user3348410
user3348410

Reputation: 2833

React / Redux how split input values with comma

i'm trying to split my input values with comma at onBlur function and set them to redux state as array but it's not working.

I read it at some topics that possible with .split(',')

my approach:

input onBlur={event = () => this.props.getValue(event.target.value)} 

my action:

export const getValue = (value) => {
  return dispatch => {
    dispatch({
      type: 'SET_VALUE',
      payload: value.split(',')
    });
  };
};

my reducer:

let initialState = {
  codes: [],
};

export default (state = initialState, action) => {
  switch (action.type) {
    case SET_VALUE:
      return { ...state, codes: action.payload };
    default:
      return state;
  }
};

what i want at the end? :

i want in my reducer like that data:

codes: [28282, 28922, 18171, 27272, ....]

but it give me now something like that:

codes: [28282 28922 18171 27272 ....]

Upvotes: 2

Views: 585

Answers (1)

Fullhdpixel
Fullhdpixel

Reputation: 813

If you want an array the action should be like this

export const getValue = (value) => {
  return dispatch => {
    dispatch({
      type: 'SET_VALUE',
      payload: value.split(' ')
    });
  };
};

Upvotes: 1

Related Questions