
Research
/Security News
11 Malicious NuGet Tools Pose as Game Cheats to Drop a Windows Host-Surveillance Payload
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.
react-stream-bloc
Advanced tools
react-stream-blocThe react-stream-bloc package contains only the functionality necessary to define Bloc models in JavaScript and TypeScript. Typically used in user interface components.
Using npm:
npm install react-stream-bloc
The basic idea behind the Bloc pattern is simple. Business logic will be isolated from UI components. First, they will use an observer to send events to the Bloc. The Bloc will then notify UI components via observables after processing the request.
The impact on the application is minimal when the business logic is separated from the UI components. You may alter the business logic whenever you want without impacting the UI components.
Because the business logic is in one location, UI components may reuse logic without duplicating code, increasing the app's simplicity.
Application needs may evolve over time, and business logic may expand. In such cases, developers can even construct many BloCs to keep the codebase clear.
Create a state file and add your variables as you like.
export interface User {
id: string;
name: string;
}
export type UserState = {
loading: boolean,
adding?: boolean,
data: User[],
message?: string,
};
export const UserInitialState: UserState = {
loading: false,
data: [],
};
Create a Bloc class file and add your functions, to change state always add this.changeState(...)
import { Bloc } from "react-stream-bloc";
import axios from "axios";
axios.defaults.baseURL = 'http://localhost:4000/api/';
export class UserBloc extends Bloc<UserState> {
private users: User[] = [];
constructor() {
super(UserInitialState);
}
async getUsers() {
this.changeState(...this.state, loading: true);
await axios.get("users")
.then((response) => {
this.changeState(this.mapToLoadedState(response.data));
})
.catch((err) => {
this.changeState(...this.state, loading: false, message: err.toString());
});
}
async addUser(data: User){
this.changeState(...this.state, adding: true);
await axios.post("user", data)
.then((response) => {
if(response.status === 200){
const user = response.data as User;
const newUsers = [user].concat(this.users);
this.changeState(this.mapToLoadedState(newUsers));
}else{
this.changeState(...this.state, adding: false);
}
})
.catch((err) => {
this.changeState(...this.state, adding: false, message: err.toString());
});
}
mapToLoadedState(users: User[]): UserState {
this.users = users;
return {
loading: false,
adding: false,
data: this.users,
};
}
}
Create a dependency provider file, here you initialize the data when your application is opened. If you want to extend the data initialization of a class or function, Easily insert it into your Bloc file.
export function provideUserBloc() {
const bloc = new UserBloc();
return bloc;
}
Create a provider file.
import { createContext } from "react-stream-bloc";
const [userContext, useUser] = createContext<UserBloc>();
const useUserBloc = useUser;
export { userContext, useUserBloc };
This file is a child that will be listening or sending values using the Bloc, all children that are listening will update the data sent or received.
import { BlocBuilder } from "react-stream-bloc";
export const UserContent = () => {
const bloc = useUserBloc();
const handleAdd = () => {
const user: User = {
id: "id",
name: "Stream Bloc",
};
bloc.addUser(user);
};
return (
<div style={{ margin: 30 }}>
<BlocBuilder
bloc={bloc}
builder={(state: UserState) => (
<div>
<button onClick={state.adding ? null : handleAdd}>
{state.adding ? "Loading..." : "Add"}
</button>
{state.loading ? <div> Loading... </div> : <div> {content} </div>}
</div>
)}
/>
</div>
);
};
In App add BlocProvider, you can add multiple providers in a list and initialize the value of DependenciesProvider.
import { BlocProvider } from "react-stream-bloc";
import { userContext } from "./UserProvider";
const App = () => {
return (
<BlocProvider
providers={[<userContext.Provider value={providerUserBloc()} />]}
>
<UserContent />
</BlocProvider>
);
};
export default App;
FAQs
React Stream Bloc
The npm package react-stream-bloc receives a total of 6 weekly downloads. As such, react-stream-bloc popularity was classified as not popular.
We found that react-stream-bloc 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.

Research
/Security News
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.

Research
/Security News
4 compromised asyncapi packages deliver miasma botnet loader on macOS, Linux and Windows.

Research
/Security News
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.