0

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

4
  • 1
    debug - stick a console.log(action.value.get(file)) in your reducer and then open the console when performing the thing that triggers the action. The code you've shown itself is fine, it's the code you haven't shown where the problem is. Commented Jan 25, 2019 at 12:27
  • @Adam there is no problem in that part. The data variable is full. When reading the initial state in local storage in componentDidMount, the following result appears. aboutMe: "test", file: {}, title: null. empty file variable Commented Jan 25, 2019 at 12:38
  • When reading the initial state - but you didn't set the file object as part of your initial state - you set it in response to an action? Commented Jan 25, 2019 at 12:41
  • When I change the file variable to blob type in the reducer, I can read it in componentDidMount. But I can read it as an empty object as a file. @Adam Commented Jan 25, 2019 at 12:54

1 Answer 1

2

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

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

Comments

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.