
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
redux-zero
Advanced tools
A lightweight state container based on Redux
Read the intro blog post
To install the stable version:
npm install --save redux-zero
This assumes that you’re using npm with a module bundler like Webpack
ES2015+ or TypeScript:
import createStore from "redux-zero"
import { Provider, connect } from "redux-zero/react"
CommonJS:
const createStore = require("redux-zero")
const { Provider, connect } = require("redux-zero/react")
UMD:
<script src="https://unpkg.com/redux-zero/dist/redux-zero.min.js"></script>
<script src="https://unpkg.com/redux-zero/react/index.min.js"></script>
Let's make an increment/decrement simple application with React:
First, create your store. This is where your application state will live:
/* store.js */
import createStore from "redux-zero";
const initialState = { count: 1 };
const store = createStore(initialState);
export default store;
Then, create your actions. This is where you change the state from your store:
/* actions.js */
export const actions = store => ({
increment: state => ({ count: state.count + 1 }),
decrement: state => ({ count: state.count - 1 })
})
By the way, because the actions are bound to the store, they are just pure functions :)
Now create your component. With Redux Zero your component can focus 100% on the UI and just call the actions that will automatically update the state:
/* Counter.js */
import React from "react";
import { connect } from "redux-zero/react";
import actions from "./actions";
const mapToProps = ({ count }) => ({ count });
export default connect(mapToProps, actions)(({ count, increment, decrement }) => (
<div>
<h1>{count}</h1>
<div>
<button onClick={decrement}>decrement</button>
<button onClick={increment}>increment</button>
</div>
</div>
));
Last but not least, plug the whole thing in your index file:
/* index.js */
import React from "react";
import { render } from "react-dom";
import { Provider } from "redux-zero/react";
import store from "./store";
import Counter from "./Counter";
const App = () => (
<Provider store={store}>
<Counter />
</Provider>
);
render(<App />, document.getElementById("root"));
Here's the full version: https://codesandbox.io/s/n5orzr5mxj
Redux Zero was based on this gist by @developit
These are unofficial tools, maintained by the community:
4.3.0
FAQs
A lightweight state container based on Redux
The npm package redux-zero receives a total of 3,023 weekly downloads. As such, redux-zero popularity was classified as popular.
We found that redux-zero demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.