How to use the react-cosmos-shared2/fixtureState.getFixtureStateProps 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 / FixtureCapture / props / index.ts View on Github external
React.useEffect(() => {
    // Create empty fixture state
    if (!fixtureState.props && elPaths.length === 0) {
      // Make sure not to override any (currently pending) fixture state props
      setFixtureState(prevFs => ({ ...prevFs, props: prevFs.props || [] }));
      return;
    }

    // Remove fixture state for removed child elements (likely via HMR)
    // FIXME: Also invalidate fixture state at this element path if the
    // component type of the corresponding element changed
    const fsProps = getFixtureStateProps(fixtureState, decoratorId);
    fsProps.forEach(({ elementId }) => {
      if (elPaths.indexOf(elementId.elPath) === -1) {
        setFixtureState(prevFs => ({
          ...prevFs,
          props: removeFixtureStateProps(fixtureState, elementId)
        }));
      }
    });

    elPaths.forEach(elPath => {
      const childEl = getExpectedElementAtPath(fixture, elPath);
      const elementId = { decoratorId, elPath };
      // Component fixture state can be provided before the fixture mounts (eg.
      // a previous snapshot of a fixture state or the current fixture state
      // from another renderer)
      if (!findFixtureStateProps(fixtureState, elementId)) {
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / CaptureProps.js View on Github external
setFixtureState(fixtureState => {
      const instanceProps = {
        instanceId,
        componentName,
        renderKey: DEFAULT_RENDER_KEY,
        values: extractValuesFromObject(children.props)
      };

      return {
        props: replaceOrAddItem(
          getFixtureStateProps(fixtureState),
          props => props.instanceId === instanceId,
          instanceProps
        )
      };
    });
  }
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / CaptureProps.js View on Github external
setFixtureState(fixtureState => {
      return {
        props: removeItemMatch(
          getFixtureStateProps(fixtureState),
          props => props.instanceId === instanceId
        )
      };
    });
  }