如何正确输入我的 useState 挂钩?
我有这种enum类型:
export enum Status {
PENDING = 'pending',
SUCCESS = 'success',
ERROR = 'error',
}
Run Code Online (Sandbox Code Playgroud)
还有useState钩子:const [isValid, setIsValid] = useState<// What to add here>(ApiStatus.PENDING);
那么useState钩子的值只能是其中一个Status值?
我在 React 项目中使用Material UI Select 组件。
我正在尝试覆盖 CSS 类.MuiPaper-root和或.MuiMenu-list.
我的选择组件:
<Select
value={selectValue}
disableUnderline
onChange={handleChange}
css={styles.select}
>
{cities?.map((city) => {
return (
<MenuItem
key={city.value}
value={city.value}
css={styles.selectItem}
>
{city.label}
</MenuItem>
);
})}
</Select>
Run Code Online (Sandbox Code Playgroud)
下面不行吗?
export default ({ theme }: StylesProps) => ({
select: css`
.MuiPaper-root {
background-color: red;
}
`,
});
Run Code Online (Sandbox Code Playgroud) 我尝试为我的 React 项目设置Mock Service Worker。我的项目不使用CRA。
我想拦截 GraphQL 请求并模拟它的响应,以使用 Cypress 创建端到端测试。
如何将文件复制mockServiceWorker.js到我的构建文件夹(使用 Webpack),如其他资产图像和字体等?
我使用了命令npx msw init build --save。然后mockServiceWorker.js已经创建了。
但是一旦我运行npm start并且我的客户端和服务器被编译,文件mockServiceWorker.js就会消失?
此外,我还需要msw在我们的验收环境中的管道中,也在管道中运行赛普拉斯端 2 端测试。
之前我能够'commit & sync'(按钮)将我的新变更从我的本地仓库转移到远程.现在我有2个新的提交,但我只看到Commit to Develop.有什么不对?
我正在将Swiper js用于我的轮播、React 和 Typescript。
在这篇文章之后,我尝试在悬停时自动stop()播放start()。我需要这种方法,因为我必须在悬停 Swiper 容器时创建一些状态。
1)ref我的组件上的属性出现打字稿错误<Swiper ref={swiperRef}>:
类型“IntrinsicAttributes & Swiper & {children?”上不存在属性“ref”?
2)如何访问swiper,以便我可以swiper.autoplay.stop();在我的函数内部使用handleMouseEnter?所以我可以这样使用:
const handleMouseEnter = () => {
swiper.autoplay.stop();
};
Run Code Online (Sandbox Code Playgroud)
或类似:
const handleMouseEnter = () => {
swiperRef.current.swiper.autoplay.stop();
};
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所拥有的沙箱。
我如何使用 Typescript 让它工作?
reactjs ×4
typescript ×2
css ×1
emotion ×1
graphql ×1
material-ui ×1
msw ×1
react-hooks ×1
swiper.js ×1