React Native component shows only one complaint instead of other more features
P粉925239921
P粉925239921 2023-08-16 09:12:20
0
1
526
<p>I'm working on a screen that gets route parameters from the previous screen for navigation but it only shows the first complaint and not any other added complaints, I don't know what is causing this issue , the following is the code: </p> <pre class="brush:php;toolbar:false;">const ECScreen = ({ route, navigation }) => { const { imageUri, complaintDate, complaintId } = route.params; const [complaints, setComplaints] = useState([]); useEffect(() => { if (imageUri && complaintDate) { const newComplaint = { id: complaints.length 1, // Assign next available ID imageUri: imageUri, date: complaintDate, status: 'Pending', }; setComplaints([...complaints, newComplaint]); } }, []);</pre>
P粉925239921
P粉925239921

reply all(1)
P粉937382230

You call this function with an empty dependency array on useEffect, which is called when the component is mounted, and the initial complaint is also empty.
Therefore, [...complaints, newComplaint] will be equal to one value, which is your newComplaint.
Please tell me which variable you wish to update complaints?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template