我有一个使用纯 css 的单选按钮,但它在第一次单击时不起作用,它只在第二次单击时起作用,不确定它是否与我的 React prop 有关:
const Radio = ({ id, name, value, checked, children }) => (
<div className="radioBtn">
<input type="radio" value={value} id={id} name={name} checked={checked} />
<label className={"radio"} htmlFor={id}>
<span className={"big"}>
<span className={"small"} />
</span>
<span>{children}</span>
</label>
</div>
);
Run Code Online (Sandbox Code Playgroud)
我用 styled-component 包装了现有组件,但我发现必须声明!important覆盖该组件的现有样式很烦人,例如
import { Row, Col, Card, Typography } from 'antd'
const { Title } = Typography
const StyledTitle = styled(Title)`
text-align: center;
margin: 50px 0 20px 0 !important;
font-weight: normal !important;
`
Run Code Online (Sandbox Code Playgroud)
很难看出哪个属性必须使用重要,我在保存文件后通过视觉变化检测到它,这太烦人了,有什么解决方案?
What is the problem with below code? I got warning by typescript when use useState
import * as React, { useState } from 'react'
const useForm = (callback: any | undefined) => {
const [inputs, setInputs] = useState({}) //error: Cannot find name 'useState'.ts(2304)
const handleInputChange = event => {
event.persist()
setInputs(inputs => ({
...inputs,
[event.target.name]: event.target.value,
}))
}
return {
handleInputChange,
inputs,
}
}
export default useForm
Run Code Online (Sandbox Code Playgroud)