
Security News
Federal Audit Finds NIST Wasted Funds With No Plan to Clear NVD Backlog
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.
@bdlite-fe/react-context-mutation
Advanced tools
to replace redux,Provider value contain useActions which is to merge context state value and useActions return an immutable function collection called `actions`
English | 中文
react-context-mutation is a lighter and more convenient state manager designed for react applications. It aims to replace the Redux in react applications and solve the problems of only one Store in Redux and Non Pluggable state maintenance in the project.
npm install @bdlite-fe/react-context-mutation --save
// ./App/context.js
import createAppContext from 'react-context-mutation';
import state from './state'; // initial state tree
import configReducer from './config-reducer'; // pre reduce config function
export default createAppContext(state, configReducer)
// ./App/index.js
import AppContext from './context'
import Header from './Header'
const { AppProvider, AppConsumer } = AppContext
export default function App() {
return (
<AppProvider>
<AppConsumer>
{({ context, useActions }) =>
<Header context={context} useActions={useActions} />
<Layout>
<Sider context={context} useActions={useActions} />
<Content>
<Router />
</Content>
</Layout>
)
}
</AppConsumer>
</AppProvider>
)
}
// ./App/state.js
export default { // initial state tree
app: {},
header: {},
sider: {},
}
// ./App/config-reducer.js
export default function configReducer({ app = {}, header = {}, sider = {} }) { // pre reduce config function
return (state) => ({
app: mergeAppConfig(app, state.app),
sider: mergeSiderConfig(sider, state.sider),
header: mergeHeaderConfig(header, state.header),
})
}
// ./Header/index.js
import createActions from './actions';
export default function Header(props) {
const { context, useActions } = props;
const { menu, currentItem } = context.header;
const actions = useActions(createActions); // actions is immutable
const handleMenuChange = useCallback((currentItem) => {
actions.changeCurrent(currentItem)
}, [actions]); // actions is immutable
return (
<header>
<Menu menu={menu} currentItem={currentItem} onMenuChange={handleMenuChange} />
</header>
)
}
// ./Header/actions.js
export default (mutation, contextRef) => ({ // `mutation`and`contextRef` from closure
changeCurrent(currentItem) {
// you can fetch data hear
mutation.header(() => ({ currentItem }));
// await for fetch has done, mutation the header context value then
}
})
The provider receives a config attribute and make the custom config merge to the abstraction of business framework.
<AppProvider config={/* initial config inner state */}>...</AppProvider>
The consumer component can subscribe to the change of context. This component allows you to subscribe to context in functional components. useActions return an immutable collection of actions used to change context value.
<AppConsumer>
{({ context, useActions, mutation }) => /* regular context to use */}
</.AppConsumer>
Context provides a way to share such values among components without explicitly passing props layer by layer through the component tree, in order to share the data that is "global" to a component tree.
<AppConsumer>
{({ context }) => // `context` contains the whole tree of state
<Header context={context} />
}}
</AppConsumer>
function Header(props) {
const { context } = props
const { menu } = context.header // get `header` namespace
return (
<header>
<Menu menu={menu} />
</header>
)
}
useActions is used to obtain the changes of update status in functional components. Accept a closure funtion that provide mutation and contextRef.
const { useActions } = props
const actions = useAction(createActions)
Mutation is used to update the status of components.
const { mutation } = props
mutation[namespace](reducer)
FAQs
to replace redux,Provider value contain useActions which is to merge context state value and useActions return an immutable function collection called `actions`
The npm package @bdlite-fe/react-context-mutation receives a total of 4 weekly downloads. As such, @bdlite-fe/react-context-mutation popularity was classified as not popular.
We found that @bdlite-fe/react-context-mutation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.