我们可以将业务登录放入故事书吗?

问题描述

export const AsyncSearch = (args) => {
  const SEARCH_URI = 'https://api.github.com/search/users';
  const [isLoading,setIsLoading] = useState(false);
  const [options,setOptions] = useState([]);
  const handleSearch = (query) => {
    setIsLoading(true);
    fetch(`${SEARCH_URI}?q=${query}+in:login&page=1&per_page=10`)
      .then((resp) => resp.json())
      .then(({ items }) => {
        const options = items.map((i) => ({
          avatar_url: i.avatar_url,id: i.id,login: i.login,}));

        setOptions(options);
        setIsLoading(false);
      });
  };
  return (
    <TypeaheadAdvancedSearch
      options={options}
      handleSearch={handleSearch}
      isLoading={isLoading}
      {...args}
    />
  );
};
AsyncSearch.args = {
  id: 'async-advance-search',isAsync: true,labelKey: 'login',searchText: 'Searching...',filterBy: () => true,};

我正在为 Typeahead 异步搜索编写故事书。由于后端 api 尚未准备好,我仅使用公共 api https://api.github.com/search/users 进行演示。但是,isLoading、options 和 handleSearch 应该作为道具传递给 AsyncSearch 这个故事。我应该模拟 API 结果而不是将以下代码直接放入故事书中吗?根据我的理解,storybook 是为独立组件构建的。

const SEARCH_URI = 'https://api.github.com/search/users';
  const [isLoading,}));

        setOptions(options);
        setIsLoading(false);
      });
  };

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...