I have a React.js app. Here is extract of the code:
const list = JsonData.map(x => Oppty(x)); // JsonData is just an array I have
...
return (
<Table>
...
<tbody>{list}</tbody>
...
</Table>
)
we render a table with say 7 cols. the first 5 cols define inputs, the last 2 cols define output when we call an API. Each row of the table is a Oppty.
Oppty is another React.FunctionComponent. It makes AJAX calls in a useEffect and updates its state (columns 6 and 7) in the callback. This causes the last 2 columns to fill in with appropriate values. This code works.
But when I change it to:
const [list, setList] = useState(JsonData.map(x => Oppty(x)));
The table renders and I see ajax calls being emitted but the last 2 columns do not update now. Why is that so and how can I fix this?