谁能告诉我使用 Typescript 将此钩子转换为类型安全版本的最佳方法。它是一个简单的切换,可在切换状态下显示不同的“事物”。
使用Toggle.js
const useToggleButton = ({on,off}) => {
const [toggle, setToggle] = React.useState(false)
const ToggleButton = () => (
<div
role="button"
onClick={() => setToggle(!toggle)}
data-testid="portal-toggle-btn"
>
{toggle? on : off}
</div>
)
return [ToggleButton, toggle, setToggle]
}
Run Code Online (Sandbox Code Playgroud)
问题是它返回一个包含组件、状态和 setState 函数的数组。我的尝试如下,但出现错误
TS2605: JSX element type 'IReturnType' is not a constructor function for JSX elements. Type 'IReturnType' is missing the
following properties from type 'Element': type, props, key
TS2739: Type '(boolean | Dispatch<SetStateAction<boolean>>)[]' is
missing the following properties from type …Run Code Online (Sandbox Code Playgroud) 谁能帮我,我真的很坚持。这是我的工具提示代码,可切换css属性显示:MouseOver和Mouse Out显示上的块:无
it('should show and hide the message using onMouseOver and onMouseOut events respectively', () => {
const { queryByTestId, queryByText } = render(
<Tooltip id="test" message="test" />,
)
fireEvent.mouseOver(queryByTestId('tooltip'))
expect(queryByText('test')).toBeInTheDocument()
fireEvent.mouseOut(queryByTestId('tooltip'))
expect(queryByText('test')).not.toBeInTheDocument()
cleanup()
})
Run Code Online (Sandbox Code Playgroud)
我不断收到错误TypeError:Expect(...)。toBeInTheDocument不是一个函数
有谁知道为什么会这样吗?我用于渲染和快照组件的其他测试均按预期工作。就像queryByText和queryByTestId一样。
谢谢
我在 Windows Subsystem For Linux (WSL) 上运行 Ubuntu。
我在终端中使用 Ubuntu 代码打开我的 VSCode。
我安装了 Python 3.8.2、pip 20.0.2 和 pipenv 版本 2020.6.2。
我创建一个文件夹或我的 Python 项目并cd进入其中。
我输入'pipenv shell'。
我收到以下错误:
Creating a virtualenv for this project…
Pipfile: /home/user/Python/ExampleOne/Pipfile
Using /usr/bin/python3 (3.8.2) to create virtualenv…
? Creating virtual environment...ModuleNotFoundError: No module named 'virtualenv.seed.via_app_data'
? Failed creating virtual environment
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到有关该问题的任何信息来解决它。我该如何解决这个问题,或者我可以在哪里更好地理解它?