How to use the react-cosmos-shared2/fixtureState.getFixtureStateStateInst function in react-cosmos-shared2

To help you get started, we’ve selected a few react-cosmos-shared2 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 react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / ComponentState.js View on Github external
const { children, state: mockedState, fixtureState } = this.props;

    // Re-render if child type or props changed (eg. via webpack HMR)
    if (
      !isEqual(nextChildren, children) ||
      !isEqual(nextMockedState, mockedState)
    ) {
      return true;
    }

    if (nextFixtureState === fixtureState) {
      return false;
    }

    const instanceId = getInstanceId(this);
    const next = getFixtureStateStateInst(nextFixtureState, instanceId);
    const prev = getFixtureStateStateInst(fixtureState, instanceId);

    // Deeper comparisons are made in componentDidUpdate to avoid redundant
    // setState calls to child ref
    return next !== prev;
  }
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / ComponentState.js View on Github external
// Re-render if child type or props changed (eg. via webpack HMR)
    if (
      !isEqual(nextChildren, children) ||
      !isEqual(nextMockedState, mockedState)
    ) {
      return true;
    }

    if (nextFixtureState === fixtureState) {
      return false;
    }

    const instanceId = getInstanceId(this);
    const next = getFixtureStateStateInst(nextFixtureState, instanceId);
    const prev = getFixtureStateStateInst(fixtureState, instanceId);

    // Deeper comparisons are made in componentDidUpdate to avoid redundant
    // setState calls to child ref
    return next !== prev;
  }
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / ComponentState.js View on Github external
componentDidUpdate({ state: prevMockedState }) {
    const { childRef } = this;
    if (!childRef) {
      return;
    }

    const { fixtureState, state: mockedState } = this.props;
    const instanceId = getInstanceId(this);
    const stateInstance = getFixtureStateStateInst(fixtureState, instanceId);

    // Reset fixture state if...
    if (
      // ...the fixture state associated with this instance (initially created
      // in handleRef) has been emptied deliberately. This is an edge case that
      // occurs when a user interacting with a fixture desires to discard the
      // current fixture state and load the fixture from scatch.
      !stateInstance ||
      // ...mocked state from fixture element changed, likely via webpack HMR.
      !isEqual(mockedState, prevMockedState)
    ) {
      return this.resetState(childRef);
    }

    this.replaceState(
      childRef,
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / ComponentState.js View on Github external
fixtureState
    } = this.props;

    this.childRef = childRef;

    // Call any previously defined ref from the child element
    if (prevRef) {
      prevRef(childRef);
    }

    if (!childRef) {
      return;
    }

    const instanceId = getInstanceId(this);
    const stateInstance = getFixtureStateStateInst(fixtureState, instanceId);

    // Fixture state already exists for this instance, which means that this
    // isn't the first child ref. The child type has likely been replaced
    // (eg. via webpack HMR). Conversely, the child instance might reset due
    // to resetting the renderKey in CaptureProps. Regardless, apply the
    // fixture state to the new child instance.
    if (stateInstance) {
      return this.replaceState(
        childRef,
        extendMockedStateWithFixtureState(mockedState, stateInstance)
      );
    }

    if (childRef.state) {
      this.initialState = childRef.state;
    }