
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
redux-inputs
Advanced tools
Redux actions and reducers for managing and validating forms and inputs
redux-inputs
works with redux to validate and store values from inputs and forms.
npm install --save redux-inputs
import React from 'react';
import ReactDOM from 'react-dom';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { createInputsReducer, connectWithInputs, ReduxInputsWrapper } from 'redux-inputs';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
// Define configuration for this form. A single input named 'email' with a default value and a function to determine validity.
const inputsConfig = {
email: {
defaultValue: 'test@example.com',
validator: (value) => typeof value === 'string' && value.indexOf('@') >= 0
}
};
// Create redux store with a reducer created with the createInputsReducer function.
const reducer = combineReducers({
inputs: createInputsReducer(inputsConfig)
});
const store = createStore(reducer, applyMiddleware(thunk));
// Define our own Field component, and wrap it in a ReduxInputsWrapper to easily create a compatible input component.
// Integration with other ui component libraries, such as material-ui, would be done here.
const Field = ({id, value, error, onChange, errorText}) => (
<div>
<input name={id} value={value} onChange={(e) => onChange(e.target.value)}/>
{error ? <p style={{color: 'red'}}>{errorText}</p> : null}
</div>
);
const ReduxInputsField = ReduxInputsWrapper(Field);
// Use the newly created ReduxInputsField by spreading in reduxInputs.inputProps.email object.
const Form = ({ inputs, reduxInputs }) => (
<form>
<ReduxInputsField errorText="Your email must contain an @" {...reduxInputs.inputProps.email}/>
<h3>Input state</h3>
<pre>{JSON.stringify(inputs, null, 2)}</pre>
</form>
);
// Hook the form up to the store with connectWithInputs, a wrapped version of react-redux's connect.
const FormContainer = connectWithInputs(inputsConfig)(s => s)(Form);
ReactDOM.render(<Provider store={store}><FormContainer /></Provider>, document.getElementById('container'));
npm i
npm run build
npm run watch-examples & npm run serve-examples
npm test
FAQs
Redux actions and reducers for managing and validating forms and inputs
The npm package redux-inputs receives a total of 110 weekly downloads. As such, redux-inputs popularity was classified as not popular.
We found that redux-inputs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.