The initial state in my component is an array of objects. I am using Redux to fetch another array of objects, as you can see in my below code. I am checking that outCalls is true, if it is I am creating a new array of objects that can be joined with the state.
However in my dependencies array it says I am missing data. If I add it, it creates a mad loop and I get errors. As it currently is, the array of objects doesn't get joined to the state.
useEffect(() => {
if(outCalls) {
const transformedOutgoingCalls = outCalls.filter(call => call.contractor._id === props.contractor._id).map(c => ({
type: 'Outgoing Call',
contact_person: c.contact_person,
logged_by: c.created_by.name,
date: c.time_created,
link: <> <LinkContainer to={`/outgoing-calls/${c._id}`} className='text-success' style={{ cursor: 'pointer'}}><Eye /></LinkContainer> </>
}))
const newData = [...data, transformedOutgoingCalls]
setData(newData)
}
}, [outCalls, props.contractor._id])
data?setData(prevData => [...prevData, tranformedOutgoingCalls])contractor._idis 1 your state will have a list only withcontractor._id1 info . Now if thecontractor._idis 2 does your state have a list with both the contractors info or just contractor 2 info ?