gpt4 book ai didi

javascript - 即使 props 显示正确,使用 PropTypes 进行类型检查也会出现错误

转载 作者:行者123 更新时间:2023-12-01 00:49:16 24 4
gpt4 key购买 nike

我正在使用 prop-types 对我的组件进行类型检查,但即使我以正确的类型正确获取了值,我仍然收到如下错误消息:

Warning: Failed prop type: The prop id is marked as required in NewChannel, but its value is undefined.

const NewChannel = props => {    
const { id } = props.match.params
return(
//some logic
)
}

NewChannel.propTypes = {
id: PropTypes.string.isRequired
}

export default React.memo(NewChannel)

当我 console.log 属性 id 时,它不是未定义的。

最佳答案

您输入检查说:props 将有一个 id 字段,例如:props.id。但是您正在从 props.match.params 获取 id。这就是它提示的原因。

关于javascript - 即使 props 显示正确,使用 PropTypes 进行类型检查也会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57115825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com