小编Jen*_*fer的帖子

反应单选按钮在第一次单击时不起作用

我有一个使用纯 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)

https://codesandbox.io/s/react-sass-34b8w

javascript css sass reactjs

4
推荐指数
1
解决办法
1848
查看次数

样式组件默认使用 !important?

我用 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)

很难看出哪个属性必须使用重要,我在保存文件后通过视觉变化检测到它,这太烦人了,有什么解决方案?

css reactjs styled-components

3
推荐指数
1
解决办法
1718
查看次数

can't use useState with typescript (Cannot find name 'useState')

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)

https://codesandbox.io/s/react-typescript-starter-lmub8

javascript typescript ecmascript-6 reactjs react-hooks

2
推荐指数
1
解决办法
4124
查看次数