Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
react-fetch-preloader
Advanced tools
Simple React component for display preloader while fetching
Library for displaying preloader when response is longer than duration.
You can see gif right above to understand idea.
npm install --save react-fetch-preloader
yarn add react-fetch-preloader
Url of response - string
React component, when response is successful render this component
Function to fetch data. Default - window.fetch
Number - if response is longer this value - show preloader(in ms). Default - 500
React component, when response is failed render this component. Default -
() => null
React component for display preloader. Default -
() => <span>Loading...</span>
withPreloader provides two extra functions:
Takes two specified params: id and url
Takes one specified param: id
You can check example of using HOC in example section
API is unstable now, so I need to figure out what will be the best realization.
You can use ShowPreloader component for this purpose
import React from 'react';
import { ShowPreloader } from 'react-fetch-preloader';
const URL = 'https://randomuser.me/api/?results=';
const SORT = [1, 10];
class App extends React.Component {
state = {
item: 10,
};
setItem = item => () => {
if (item !== this.state.item) {
this.setState({ item });
}
};
render() {
const { item } = this.state;
return (
<div className="App">
<div className="sort">
{SORT.map(sort => (
<button
type="button"
onClick={this.setItem(sort)}
key={sort}
>
Load {sort} items
</button>
))}
</div>
<ShowPreloader
duration={300}
preloader={YourPreloaderComponent}
loaded={LoadedComponent}
errored={ErrorComponent}
url={`${URL}${item}`}
/>
</div>
);
}
}
You can use HOC component to fetch data in different places of your App
import React from 'react';
import ReactDOM from 'react-dom';
import { withPreloader } from 'react-fetch-preloader';
import Preloader from './Preloader';
import Card from './Card';
import './styles.css';
const Error = data => {
console.log(data);
return <h1>Oops :( Error</h1>;
};
class App extends React.Component {
preload = (id, url) => () => {
this.props.preload(id, url);
};
render() {
const { renderPreloader } = this.props;
return (
<div className="App">
<div className="sort">
<button
type="button"
onClick={this.preload(1, 'https://randomuser.me/api/?results=20')}
>
Load 20 items
</button>
<button
type="button"
onClick={this.preload(2, 'https://randomuser.me/api/?results=10')}
>
Load 10 items
</button>
</div>
<div>Some content here</div>
{renderPreloader(1, {
duration: 0,
})}
<div>And here...</div>
{renderPreloader(2)}
</div>
);
}
}
const WrappedApp = withPreloader(App);
const rootElement = document.getElementById('root');
ReactDOM.render(
<WrappedApp
preloadOptions={{
duration: 1000,
preloader: Preloader,
loaded: Card,
errored: Error,
}}
/>,
rootElement,
);
You can clone this repository and check example
git clone https://github.com/mmarkelov/react-preloader.git
cd ./react-preloader/example
yarn && yarn run dev
FAQs
Simple React component for display preloader while fetching
The npm package react-fetch-preloader receives a total of 3 weekly downloads. As such, react-fetch-preloader popularity was classified as not popular.
We found that react-fetch-preloader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.