storybook-addon-mock icon indicating copy to clipboard operation
storybook-addon-mock copied to clipboard

Suggestion: Refresh component when pausing/activating requests mocking.

Open AlexandreSi opened this issue 3 years ago • 0 comments

Hi!

Could it be possible to add an option so that, when pausing/activating requests mocking, the story is refreshed. It would be very convenient for a React component that implement such hooks:

const ResourceDisplayer = () => {
  const [resources, setResources] = useState<?Array<Resource>>(null);
  const [displayError, setDisplayError] = useState<boolean>(false);

  const fetchResources = useCallback(async () => {
    try {
      setDisplayError(false);
      const resources = await getResources();
      setResources(resources);
    } catch (err) {
      console.log(`Error when fetching resources: ${err}`);
      setDisplayError(true);
    }
  }, []);

  useEffect(
    () => {
      fetchResources();
    },
    [fetchResources]
  );
  return ( ... )
}

AlexandreSi avatar Nov 19 '21 10:11 AlexandreSi