Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
storybook-react-context
Advanced tools
Manipulate React context inside Storybook. Read state and dispatch updates from outside of React component.
Manipulate React context inside Storybook. Read state and dispatch updates from outside of React component.
npm install -D storybook-react-context
Add withReactContext
decorator where needed, per component or globally.
import { withReactContext } from 'storybook-react-context';
export default {
title: 'some story',
decorators: [withReactContext],
};
withReactContext
takes an argument which is an object with the following optional keys:
context
- custom context returned by React.createContext
reducer
- custom reducer (defaults to a simple assignment of dispatch action on the current state)initialState
- initial state to use in useReducer for context provider valueInitial context state can also be set in parameters using initialState
key:
someComponent.parameters = {
initialState: {
defaultValue: true,
},
};
When both initialState
values (in decorator argument and parameters) are objects
they are combined (assigned), otherwise the either initialState
in parameters or
decorator argument will be used (in that order).
Component will be wrapped with another component which uses the context hook and returns
it to the story via story context as the result of React.useReducer
with reducer
function and initialState
.
import { withReactContext } from 'storybook-react-context';
export const myStory = (_, { context: [state, dispatch] }) => (
<button onClick={() => dispatch({ text: 'Changed' })}>{state.text}</button>
);
myStory.decorators = [withReactContext({
initialState: {
title: 'Initial #1'
}
})];
myStory.parameters.initialState = {
initialState: {
text: 'Initial #2',
},
};
FAQs
Manipulate React context inside Storybook. Read state and dispatch updates from outside of React component.
The npm package storybook-react-context receives a total of 21,875 weekly downloads. As such, storybook-react-context popularity was classified as popular.
We found that storybook-react-context demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.