How to use the react-component-tree.injectState function in react-component-tree

To help you get started, we’ve selected a few react-component-tree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NiGhTTraX / react-test-buffet / tests / helpers.js View on Github external
try {
    component = React.render(React.createElement(
        Component, props, fixture.children),
        _container);
  } catch (e) {
    throw new Error(
      `The component threw an exception while rendering:\n ${e.message}`);
  }

  if (fixture.state) {
    // Injecting state will trigger a new render cycle and we only care about
    // the calls caused by the last render
    sandbox.reset();

    ComponentTree.injectState(component, fixture.state);
  }

  return component;
}
github skidding / flatris / src / components / FlatrisStatePersistor.jsx View on Github external
componentDidMount() {
    $(window).on('unload', this.onUnload);

    // Unload previous state from local storage if present, otherwise
    // a blank Flatris instance will be rendered
    var prevState = localStorage.getItem('flatrisState');
    if (prevState) {
      ComponentTree.injectState(this.refs.flatrisStatePreview,
                                JSON.parse(prevState));
    }
  }
github react-cosmos / react-cosmos / packages / react-cosmos / src / components / proxies / StateProxy.jsx View on Github external
onComponentRef(componentRef) {
      const {
        fixture,
        onComponentRef,
        disableLocalState,
      } = this.props;

      // Ref callbacks are also called on unmount with null value
      if (componentRef && !disableLocalState) {
        // Load initial state right after component renders
        const fixtureState = fixture[fixtureKey];
        if (fixtureState) {
          ReactComponentTree.injectState(componentRef, fixtureState);
          this.scheduleStateUpdate();
        } else {
          const initialState = this.getStateTree(componentRef);
          // No need to poll for state changes if entire component tree is stateless
          if (initialState) {
            this.updateState(initialState);
          }
        }
      }

      if (!componentRef) {
        clearTimeout(this.timeoutId);
      }

      // Bubble up component ref
      onComponentRef(this.componentRef = componentRef);
github skidding / react-component-playground / src / components / component-playground.jsx View on Github external
_injectPreviewChildState: function() {
    var state = this.state.fixtureContents.state;

    if (!_.isEmpty(state)) {
      ComponentTree.injectState(this.refs.preview, _.cloneDeep(state));
    }
  },

react-component-tree

Serialize and reproduce the state of an entire tree of React components

MIT
Latest version published 7 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages