Closed javatlacati closed 3 months ago
Hi, I understand your confusion. I would recommend this read
To get your example working, just use an updater function instead of reading and updating the state at the same time:
function addSubsidiaryToChain(subsidiary: Subsidiary) {
setRecoil(subsidiariesState, (subsidiaries) => [...subsidiaries, subsidiary]);
}
function addEmployeeToChain(employee: Employee) {
setRecoil(employeesState, (employees) => [...employees, employee]);
}
@javatlacati Just updated the README as well. Thanks
Having two similar recoil states
and calling with equivalent code an add element function
The first function adds elements at the end of the array while the second will only replace elements.
Tested in edge version 126.0.2592.102
https://stackblitz.com/edit/vite-react-ts-ervyuz?file=package.json,src%2Fdata_loader.ts