Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
react-native-use-stored-state
Advanced tools
State hook for react-native and react-native-web that allows easy usage of state that is persisted. It is a wrapper of async-storage which simplifies its usage for objects and loading states.
State hook for react-native and react-native-web that allows easy usage of state that is persisted. It is a wrapper of @react-native-async-storage/async-storage
which makes it easier to deal with objects and loading states.
Installation:
yarn add react-native-use-stored-state
Usage:
const reducer = (prevState, action) => {
switch (action.type) {
case 'age':
return {...prevState, active: action.payload.age };
}
}
const MyComponent = () => {
const [myName, setMyName, myNameIsLoaded, unsetName] = useStoredState('NAME_KEY_FOR_ASYNC_STORAGE');
const [myState, dispatch, myStateIsLoaded, unsetMyState] = useStoredReducer('MY_STATE_KEY_FOR_ASYNC_STORAGE', reducer, {
active: false,
});
if (!myNameIsLoaded || !myStateIsLoaded) {
return <Loading />;
}
const onNameChange = (name) => {
setMyName(name);
};
const onStateChange = (key, value) => {
dispatch({
type: 'abc',
payload: {
[key]: value,
}
});
};
const onClear = () => {
unsetName();
unsetMyState();
};
return (
<Container>
<Input value={myName} onChange={onNameChange} />
<Checkbox value={myState.active} onChange={(value) => onStateChange('active', value)} />
<Input value={myState.age} onChange={(value) => onStateChange('age', value)} />
<Input value={myState.year} onChange={(value) => onStateChange('year', value)} />
<Button onPress={onClear}>Clear</Button>
</Container>
);
}
this in typescript would be:
interface MyState {
active: boolean;
age?: number;
}
const ReducerAction = 'age' | 'year';
const reducer = (prevState: MyState, action: ReducerAction): MyState => {
switch (action.type) {
case 'age':
return {...prevState, active: action.payload.age };
}
}
const MyComponent = (): ReactElement => {
const [myName, setMyName, myNameIsLoaded] = useStoredState<string>('NAME_KEY_FOR_ASYNC_STORAGE');
const [myState, setMyState, myStateIsLoaded] = useStoredReducer<MyState, ReducerAction>('MY_STATE_KEY_FOR_ASYNC_STORAGE', reducer, {
active: false,
});
if (!myNameIsLoaded || !myStateIsLoaded) {
return <Loading />;
}
const onNameChange = (name: string) => {
setMyName(name);
};
const onStateChange = <K extends keyof MyState>(key: K, value: MyState[K]) => {
dispatch({
type: 'abc',
payload: {
[key]: value,
}
});
};
const onClear = () => {
unsetName();
unsetMyState();
};
return (
<Container>
<Input value={myName} onChange={onNameChange} />
<Checkbox value={myState.active} onChange={(value) => onStateChange('active', value)} />
<Input value={myState.age} onChange={(value) => onStateChange('age', value)} />
<Input value={myState.year} onChange={(value) => onStateChange('year', value)} />
<Button onPress={onClear}>Clear</Button>
</Container>
);
};
FAQs
State hook for react-native and react-native-web that allows easy usage of state that is persisted. It is a wrapper of async-storage which simplifies its usage for objects and loading states.
The npm package react-native-use-stored-state receives a total of 8 weekly downloads. As such, react-native-use-stored-state popularity was classified as not popular.
We found that react-native-use-stored-state 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.