Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-incrementor
Advanced tools
Component to build simple, flexible, and accessible incrementor components
You want an incrementor component that's simple and gives you complete control over rendering and state.
This follows the controlled prop pattern
and render prop pattern
to expose an API that
renders nothing and simply encapsulates the logic of a incrementor component.
This module is distributed via npm
, which is bundled with node
, and
should be installed as one of your project's dependencies
:
npm install --save react-incrementor
This package also depends on
react
andprop-types
. Please make sure you have those installed as well.
import React from 'react';
import { render } from 'react-dom';
import Incrementor from 'react-incrementor';
function BasicIncrementor() {
return (
<Incrementor
render={({ value, getDecrementerProps, getIncrementerProps }) => {
return (
<div>
<div>
<span>{value}</span>
</div>
<div>
<button {...getDecrementerProps()}>Minus 1</button>
<button {...getIncrementerProps()}>Plus 1</button>
</div>
</div>
);
}}
/>
);
}
render(<BasicIncrementor />, document.getElementById('root'));
react-incrementor
is the only component. It doesn't render anything itself, it just
calls the render
function and renders that.
number
| defaults to0
The default value
state.
number
| control prop
react-incrementor manages its own state internally and calls your onChange
handler whenever the value
state changes. Pass the value
state as a prop
and that state becomes controlled. It is your responsibility to keep the value
updated by re-rendering the component.
function(value: number)
| optional
Called at interaction with the incrementor
function({})
| required
This is called with an object that exposes the public API of this component.
The function is passed as the render prop:
<Incrementor render={(value) => {/* awesome code */}} />
property | category | type | description |
---|---|---|---|
value | state | boolean | The current value state of the incrementor |
getIncrementerProps | prop getter | function(props: object) | returns the props you should apply to the incrementer button element you render. Includes aria- attributes |
getDecrementerProps | prop getter | function(props: object) | returns the props you should apply to the decrementer button element you render. Includes aria- attributes |
This was build as a learning exercise for the controlled prop pattern
and render prop pattern
. It is heavily influenced by Kent C. Dodds's react-toggled component
MIT
FAQs
Component for building flexible incrementor components
The npm package react-incrementor receives a total of 2 weekly downloads. As such, react-incrementor popularity was classified as not popular.
We found that react-incrementor 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.