
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
react-redux-spinner
Advanced tools
A spinner and loading bar for any long running tasks. For react with redux
A simple spinner for any "long" running tasks (such as fetching data off a server).
DEMO: https://storytel.github.io/react-redux-spinner
npm install react-redux-spinner --save
Import the library.
import {
Spinner, // The React component
pendingTasksReducer, // The redux reducer
pendingTask, // The action key for modifying loading state
begin, // The action value if a "long" running task begun
end, // The action value if a "long" running task ended
endAll // The action value if all running tasks must end
} from 'react-redux-spinner';
Install the reducer to the store. Make sure it reduces the pendingTasks
key.
This is best done using combineReducers
from redux
.
import { createStore, combineReducers } from 'redux'
const reducer = combineReducers({
pendingTasks: pendingTasksReducer
});
const store = createStore(reducer);
Put the Spinner
component anywhere in your application.
import React from 'react';
const App extends React.Component {
render() {
return (<Spinner />)
}
}
Start a long running task. This will typically be when you begin fetching data from a server.
This will increase the pending tasks counter by 1. The spinner will be shown when the pending tasks is greater than 0.
store.dispatch({
type: 'ANY_OF_YOUR_ACTION_TYPES'
[ pendingTask ]: begin // Make sure you embrace `pendingTask` in brackets [] to evaluate it
// Any additional key/values may be included here
});
When your long running task is done.
store.dispatch({
type: 'ANY_OF_YOUR_ACTION_TYPES_DONE'
[ pendingTask ]: end // Bracket [] embrace, remember?
// Any additional key/values may be included here
});
When you want to force the finish of all pending tasks (for example: with a global error).
store.dispatch({
type: 'ANY_OF_YOUR_ACTION_TYPES_FINISH'
[ pendingTask ]: endAll // Bracket [] embrace, remember?
// Any additional key/values may be included here
});
By default, no styling is included. You can either roll your own. Feel free to use the default css as boilerplate.
If you're using webpack as your bundler, you could use style-loader and css-loader to include the default css.
In webpack.config.js
:
// ...
module: {
rules: {
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
}
}
and in your css files (the tilde ~
means "look in node_modules"):
@import '~react-redux-spinner/dist/react-redux-spinner.css';
Maybe you cannot have the pendingTask
in the root of your actions.
For instance, if you're trying to follow the Flux Standard Actions
you're not allowed to have anything in the root except type
, payload
, error
and meta
.
It would then be prudent to put pendingTask
in meta
.
To get the reducer to look here instead you need to configure it to do so with configurablePendingTasksReducer
.
import { configurablePendingTasksReducer } from 'react-redux-spinner';
import { createStore, combineReducers } from 'redux'
const pendingTasks = configurablePendingTasksReducer({ actionKeyPath: [ 'meta' ] });
const reducer = combineReducers({
pendingTasks: pendingTasksReducer
});
const store = createStore(reducer);
and then dispatch actions:
store.dispatch({
type: 'ANY_OF_YOUR_ACTION_TYPES'
meta: {
[ pendingTask ]: begin
}
});
The actionKeyPath
may be as deeply nested as required.
For instance, if you'd like to have the keys in meta.async
, you'd provide actionKeyPath: [ 'meta', 'async' ]
and then dispatch actions with { meta: { async: { [ pendingTask ]: begin } } }
begin
or end
variables?import rrs from 'react-redux-spinner';
dispatch({
type: 'ACTION_TYPE',
[ rrs.pendingTask ]: rrs.begin
});
import { pendingTasksReducer as pendingTasks } from 'react-redux-spinner';
const reducer = combineReducers({ pendingTasks });
#nprogress .bar {
background-color: #f4590a;
}
#nprogress .spinner-icon {
border-top-color: #f4590a;
border-left-color: #f4590a;
}
#nprogress .peg {
box-shadow: 0 0 10px #f4590a, 0 0 5px #f4590a;
}
render() {
return (<Spinner config={{ trickleRate: 0.02 }} />)
}
FAQs
A spinner and loading bar for any long running tasks. For react with redux
We found that react-redux-spinner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.