Can Kurucu
Can Kurucu

Reputation: 75

How to add file into state on React-Redux

I have a formdata object. I'm moving this into a reducer with redux. Then can I define the file contained in this formData into INITIAL_STATE?

var INITIAL_STATE = { stepOneInformation: {} }

REDUCER

case STEP_ONE_SET_DATA:    
        const data = {
            file : action.value.get('file'),
            aboutMe : action.value.get('aboutMe'),
            title : null
        }
        return {
            ...state,
            stepOneInformation: data
        }

I defined the file in the formdata object to the data variable parameter. But the file object looks blank when reading the state

Upvotes: 0

Views: 290

Answers (1)

Gleb Ermolaev
Gleb Ermolaev

Reputation: 55

You shouldn't try to read your initial state to get the updated data, because it is stored in the state variable of the store. It's also a bad practice to get data directly from the state, use mapStateToProps instead

Upvotes: 2

Related Questions