An open API service indexing awesome lists of open source software.

https://github.com/icyjoseph/lazy-render-with-img

Lazy render using native image lazy loading
https://github.com/icyjoseph/lazy-render-with-img

lazy lazy-render native-lazy-loading react vite

Last synced: 3 months ago
JSON representation

Lazy render using native image lazy loading

Awesome Lists containing this project

README

        

# Lazy Render

Perhaps an anti pattern, but this project shows how to use `loading=lazy` on an `img` element to lazy render a component.

In this particular case, the lazy rendered component, triggers a call to `react-toastify`.

```tsx
import { ToastContainer, toast } from "react-toastify";
import { LazyRender } from "native-lazy-render";

const HelloWorld = () => {
useEffect(() => {
toast("Hello World!", { toastId: "Hello" });
}, []);

return null;
};

export default function App() {
const [show, setShow] = useState(true);

useEffect(() => {
if (!show) {
const handler = () => setShow(true);
window.addEventListener("scroll", handler);
return () => window.removeEventListener("scroll", handler);
}
}, [show]);

return (
<>


Lazy Render


Scroll down


setShow(false)}>Reload

{show && (



)}

End
>
);
}
```