
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@bloc-state/react-bloc
Advanced tools
React components and hooks for bloc-state
npm install @bloc-state/react-bloc
const UserPage = () => (
<BlocProvider
bloc={[UserBloc]} // pass N number of bloc classes
onCreate={(get) => get(UserBloc).add(new UserInitializedEvent())}
>
<SomeChildComponent />
</BlocProvider>
)
const UserPage = () => {
const history = useHistory()
const snackbar = useSnackbar()
return (
<BlocProvider
bloc={[ UserBloc ]}
onCreate={(get) => {
get(UserBloc).add(new UserInitializedEvent())
}
>
<BlocListener
bloc={UserBloc}
listenWhen={(previous, current) => current.status === "failure"}
listener={(get, state) => snackbar.open(state.error?.message) }
>
<SomeChildComponent />
</BlocListener>
</BlocProvider>
)
}
// or if you need multiple bloc listeners, create siblings
const UserPage = () => {
const history = useHistory()
return (
<BlocProvider
bloc={[ UserBloc ]} // pass N number of bloc classes
onCreate={(get) =>
get(UserBloc).add(new UserInitializedEvent())
}
>
<>
<BlocListener
bloc={UserBloc}
listenWhen={(previous, current) => !current.data.isAuthenticated}
listener={(get, state) => history.push("/login")}
/>
<BlocListener
bloc={UserBloc}
listenWhen={(previous, current) => previous.data.randomeData && !current.data.someOtherData}
listener={(get, state) => openSnackBar(state)} // some other side-effect
/>
<SomeChildComponent />
</>
</BlocProvider>
)
}
export const SomeComponent = () => {
const bloc = useBlocInstance(UserBloc) // returns the bloc instance from context
return (
<>
<a onClick={() => bloc.add(new UserClickedEvent())}></a>
</>
)
}
export const SomeComponent = () => {
const state = useBlocValue(UserBloc) // returns the current state value from a bloc instance
return (
<>
<p>User: {state.name}</p>
</>
)
}
export const SomeComponent = () => {
const emit = useSetValue(CounterCubit) // returns the emitter method from a bloc/cubit
// should only be used with cubits, blocs use events to change state in a bloc
return (
<>
<a onClick={() => emit((count) => count + 1)}></a>
</>
)
}
type SomeComponentProps = {
id: number
}
export const SomeComponent = ({ id }: SomeComponentProps) => {
const lastName = useBlocSelector(UserBloc, {
// required: a pure selector function for narrowing your state
selector: (state) => state.name.last,
// optional: decide which state changes a component should react to
// it will rerender for all state changes by default
listenWhen: (state) => state.id === id,
// optional: defaults to false, if set to true components will suspend when suspendWhen returns true
suspend: true,
// optional: if suspend is enabled, decide when a component should suspend
suspendWhen: (state) => state.status === "loading",
})
return (
<>
<p>{lastName}</p>
</>
)
}
export const SomeComponent = () => {
// returns a tuple with the state as first index and the bloc instance as second index
// optionally takes a useBlocSelector config object, so it can be used to read as well as emit events with bloc intance
const [id, bloc] = useBloc(UserBloc, {
selector: (state) => state.data.id,
})
return (
<>
<a onClick={() => bloc.add(new UserLoggedOutEvent(id))}></a>
</>
)
}
FAQs
React adapter for bloc-state.
The npm package @bloc-state/react-bloc receives a total of 27 weekly downloads. As such, @bloc-state/react-bloc popularity was classified as not popular.
We found that @bloc-state/react-bloc 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.