Moweyy
Moweyy
KPCKevin Powell - Community
Created by Moweyy on 1/25/2024 in #front-end
LocalStorage and useEffect
In a typical CRUD scenario, one would be using the above mentioned like this: • useEffect => On load: check if localStorage data exists, then parse it and save in state. • useEffect => Listens for changes in state data, then saves it to localStorage. How can I prevent the second useEffect from running after the first on initial load? Let's say I have already added some data in localStorage. When my app loads, it fetches said data and calls setState to save it in my local state. Since this data is in the dependency array of the second useEffect, it triggers it, saving nothing. Thanks!
3 replies
KPCKevin Powell - Community
Created by Moweyy on 7/21/2023 in #front-end
Srcset not working
Hi! I'm trying to display webp images with fallback for older browsers, but I can't seem to get it to target my webp images on browsers that support them. It always falls back to my jpg images. According to mdn, I don't need to provide a condition descriptor (eg: 1x, 450w, etc) as it will be assigned a default descriptor of 1x. I have no need for that anyway as I am only using 1 image that doesn't vary too much in size. Here's the source code:
<picture>
<source srcset="./assets/home/district-estate.webp" src="./assets/home/district-estate.webp" type="image/webp" class="d-none d-lg-block img-fluid" alt="mountain hill">
<source srcset="./assets/home/district-estate-mobile.jpg" class="d-lg-none img-fluid" alt="mountain hill" type="image/jpg">
<img src="./assets/home/district-estate.jpg" class="d-none d-lg-block img-fluid" alt="mountain hill">
</picture>
<picture>
<source srcset="./assets/home/district-estate.webp" src="./assets/home/district-estate.webp" type="image/webp" class="d-none d-lg-block img-fluid" alt="mountain hill">
<source srcset="./assets/home/district-estate-mobile.jpg" class="d-lg-none img-fluid" alt="mountain hill" type="image/jpg">
<img src="./assets/home/district-estate.jpg" class="d-none d-lg-block img-fluid" alt="mountain hill">
</picture>
Thank you!
2 replies