I want to read the first value from a list stream in useEffect
to select the first value in the list returned. How do I do this differently.
Shows an error on restart.
I am using hooks_riverpod
final _locations = useProvider(locationsProvider); // provides AsyncValue<List<FacilityLocation>>
final _selectedLocationID = useState('');
useEffect(() {
_locations.when(
data: (locations) {
final _location = locations[0];
return _selectedLocationID.value = _location.locationID;
},
loading: null,
error: (err, stack) => null,
);
return;
}, []);