
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
Hyperwrap embodies the principles of hyperapp and transfers them to react, turning react into a simple to use functional framework.
The easiest way to get going is to install the seed project using douglas.
douglas installs npm modules as ready to roll projects...
If you don't have douglas, install globally with npm i -g douglas
Install hyperwrapped-react (seed project)
douglas get hyperwrapped-react
If you haven't used parcel-bundler before, then install globally with
npm i -g parcel-bundler... then ...
npm start
Hyperwrap is an app function that wraps around React.
When Hyperwrap's state changes - it rerenders React.
A typical entry index.tsx looks like...
import { app } from "hyperwrap";
import { initialState } from "./src/state/state";
import { View } from "./src/components/view/view.component";
app(initialState, View, document.getElementById('app'));
initialState is just a plain js object.
View is just a plain React functional component
In Hyperwrap, actions are just functions.
Those functions can change global state, which in turn rerenders the application.
Remember - in Hyperwrapp, state is global.
getState() gets global state and updateState() updates it...
import * as React from 'react';
import { State } from '../../../state/state';
import { getState, updateState } from 'hyperwrap';
export const Home = () => {
const changeThing = (e: any, thing: string) => { updateState('thing', thing); };
return (
<div>
<p>{getState().thing}</p>
<button onClick={(e) => {changeThing(e, 'bob')} }>push</button>
</div>
);
};
We've changed the above code, so we can inject both state and actions into the functional component.
This makes the component pure, and easier to test.
Note that the function changeThing has also been moved out to it's own module.
We then assign changeThing to an actionsCollection, which we inject in as actions.
Since typescript thinks that
stateandactionsmay be undefined, we include the lines ...
...
const _state = state || getState();
const _actions = actions || actionsCollection;
...
This ensures that
_stateand_actionsare definitely NOT undefined.
We then use_stateand_actionsthroughout the component.
import * as React from 'react';
import { State } from '../../../state/state';
import { Actions } from '../../../actions/actions';
import { getState } from 'hyperwrap';
import { changeThing } from './change-thing.function';
interface Props {
state?: State;
actions?: Actions;
}
const actionsCollection = {
changeThing: changeThing
}
export const Home = (
{state, actions}: Props = {
state: getState(),
actions: actionsCollection
}
) => {
const _state = state || getState();
const _actions = actions || actionsCollection;
return (
<div>
<p>{_state.thing}</p>
<button onClick={(e) => {_actions.changeThing(e, 'bob')} }>push</button>
</div>
);
};
To update state, specify the node in the state object to update, followed by the value.
updateState('deep/nested/thing', newValue);
Adding nodes - Use the above. If parent nodes aren't created yet, they will be created for you.
Deleting nodes - Make the newValue undefined. Any parent node clean up will also be taken care of.
By default hyperwrap will rerender your React app on state change.
If however you are making multiple state changes at once - this is not ideal.
Instead pass the { rerender: false } flag to stop the app from rerendering...
updateState('deep/nested/thing', newValue, {rerender: false});
The following can be used to update multiple state nodes, before re-rendering...
updateMulti([
{ node: 'deep/nested/thing', updateValue: newValue1 },
{ node: 'another/deep/nested/thing', updateValue: newValue2 }
]);
Again, if you don't want to rerender after the state updates - pass the { rerender: false } flag.
e.g.
updateMulti([
{ node: 'deep/nested/thing', updateValue: newValue1 },
{ node: 'another/deep/nested/thing', updateValue: newValue2 }
], {
rerender: false
});
FAQs
Makes React simple and functional
The npm package hyperwrap receives a total of 2 weekly downloads. As such, hyperwrap popularity was classified as not popular.
We found that hyperwrap 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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.