Skip to main content

Reactant Hooks

Reactant provides useConnector for injecting the component props in the ViewModule.

API

Example

@injectable()
class FooView extends ViewModule {
@state
key = 'str';

@action
setValue(value: any) {
this.key = value;
}

component() {
const { key } = useConnector(() => ({ key: this.key }));
// or `const key = useConnector(() => this.key);`
return <span>{key}</span>;
}
}

const container = document.createElement('div');
document.body.appendChild(container);

act(() => {
createApp({
modules: [],
main: FooView,
render,
}).bootstrap(container);
});

expect(container.querySelector('span')?.textContent).toBe('str');

React Hooks

React Hooks are in-built functions that allow React developers to use state and lifecycle methods inside functional components.