Skip to content

Instantly share code, notes, and snippets.

@ilyalesik
Last active June 28, 2020 14:58
Show Gist options
  • Save ilyalesik/c0f7393f15856de7296249f987f19c18 to your computer and use it in GitHub Desktop.
Save ilyalesik/c0f7393f15856de7296249f987f19c18 to your computer and use it in GitHub Desktop.
import React from "react";
const LoadingWrapper = (props) => {
const {as, loading, ...otherProps} = props;
const el = React.useRef();
React.useEffect(() => {
el.current && el.current.setAttribute("loading", loading);
}, [loading]);
const Component = as;
return <Component ref={el} {...otherProps} />
}
...
<LoadingWrapper as={"div"} loading={...} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment