I have two array in different files ! First in the file named maturi.js and it looks like
const BEL2010YEAR12 = [
{
question: "",
hasImage: false,
isAnswered: false,
isTextQuestion: true,
text: "",
answers: [
{
id: "1",
text: "",
correct: false,
userInput: false,
},
{
id: "2",
text: "",
correct: false,
userInput: false,
},
{
id: "3",
text: "",
correct: false,
userInput: false,
},
{
id: "4",
text: "",
correct: true,
userInput: false,
},
],
},
];
export default {
BEL2010YEAR12,
};
Second file is my App.js where i called maturi (file above) like
import { BEL12 } from "../maturi";
Then i created another array to copy first which name is BEL2010YEAR12 (from file above) So
const [questions, setQuestions] = useState(BEL12.BEL2010YEAR12);
The problem is when i edit questions array it is affected to the BEL12.BEL2010YEAR12 array. How is this possible. I am confused. Why questions array changed BEL12.BEL2010YEAR12 ? For example if i edit questions like
questions[0].question = "example";
setQuestions(questions);
It will changed array BEL2010YEAR12 . I dont want that ! Why it changed it ?