0

I have a 5 step form in React. Form data is being stored in redux. I also have a file upload on step 3. Step x is unmounted when I go to step x+1. The goal is to perform file upload on the last, 5th step, when I have no mounted input file. My plan is to store event.target.files in redux and access it on the final step and use this object to upload file. Will it work, will browser allow me to do such trick?

Thanks in advance

1
  • Actually it is a very larve app, this case is just a tiny part i'm actually working on at the moment. :) Commented Jul 8, 2020 at 19:36

1 Answer 1

1

It might not be feasible, but with React's new Hooks API, Redux isn't necessary for smaller web applications anymore. I'd consider migrating away from Redux in favor of the useState hook.

If you do it this way, you can have one component for the overall form and several children component for each of the five steps. On the last step, you can upload the files from the component state, rather than from the Redux store.

That being said, if you decide to stick with Redux, you'll have to make sure you dispatch an action as soon as the file is uploaded to populate it in the store. Once you're on the final step, dispatch an action to upload the file from the store to wherever it needs to go.

Here's an example of how to use useState: This is taken directly from React's documentation: `

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

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

3 Comments

Welcome to the community. If possible, can you provide a short snippet of how useState is used?
Actually it is a very larve app, this case is just a tiny part i'm actually working on at the moment. :)
Ah understood. In that case, you'll have to dispatch one action to put the file in the store and another one to upload the file from the store to your cloud storage (or wherever it needs to go).

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.