Tuesday 31 July 2018

Unwanted React Component rerender?

So this is a form where the user can add sections to add a question (to build a quiz) and I notice that when I fill in the Answer Choices and put a file in my dropZone (drop works but doesn't update correctly, you can ignore this) the Answer Choices and dropZone rerender and the fields like refresh and become empty.

I am not entirely sure why this is happening, i have tried looking at similar issues but I couldn't get it to work. Here is my CodeSandbox with my App.

I am thinking that it may be the addQuestion function in my Questions component. Here's the code for that:

  addQuestion = question => {
    questionIdx++;
    var newQuestion = { uniqueId: uuid(), question: "" }
    this.setState(prevState => ({
      questions: [...prevState.questions, newQuestion]
    }));
    return { questions: newQuestion }
  };

I am new to React and Js so any tips/explanations will do loads of help. Thanks!



from Unwanted React Component rerender?

No comments:

Post a Comment