reactant
Version:
A framework for building React web applications
44 lines • 1.21 kB
TypeScript
import { Container } from 'reactant-module';
import { ShallowEqual } from '../interfaces';
/**
* ## Description
*
* `useConnector` is a React Hooks, which you can use to inject any shared state and derived data that you want to render using.
* And it supports both `useConnector(() => this.renderPropsValue)` and `useConnector(() => this.getMapStateToProps())` uses.
*
* ## Example
*
* ```tsx
* @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');
* ```
*/
export declare function useConnector<T>(selector: (container: Container) => T, shallowEqual?: ShallowEqual): T;
//# sourceMappingURL=useConnector.d.ts.map