Not sure how to get value from store and make it reactive.
I have a leaflet map and I want to display label of selected location.
I can see in the store with dev tools that value is updated over there but it’s not update in component.
Not sure what am I doing wrong here?
By my understanding using:
const locationLabel = useStore('selectedLocation');
should subscribe to value change update, and then simple displaying in template should work like this: {locationLabel}
However I can’t get the value.
I’ve tried using useEffect(), but that didn’t bring any joy either.
// address-search.tsx
// Address Search Input
const AddressSearch = () => {
useEffect(() => {
map.on('geosearch/showlocation', function (ev) {
f7.store.dispatch('setSelectedLocation', ev.location.label);
});
}, []);
return null;
};
export default AddressSearch;
// tab-location.tsx
// Tab with Map location
const TabLocation = () => {
//
const locationLabel = useStore('selectedLocation');
// Define state for the value to be displayed
const [selectedLocation, setSelectedLocation] = useState(
useStore('selectedLocation')
);
// Use the useEffect hook to update the displayed value when the store value changes
useEffect(() => {
setSelectedLocation(selectedLocation);
}, []);
return (
<div>
{selectedLocation}
{locationLabel}
</div>
);
};
export default TabLocation;