简体   繁体   English

什么是props.values反应?

[英]What are props.values in react?

I have a project with react, redux and redux-form. 我有一个带有react,redux和redux-form的项目。 Playing with redux-form shouldValidate function, I wanted to see what was inside props and nextProps. 玩redux形式的shouldValidate函数时,我想看看props和nextProps里面有什么。 The default implementation of shouldValidate function handles variables props.values. shouldValidate函数的默认实现处理变量props.values。 I wonder what those props.values are? 我不知道这些props.values是什么? Are they a react thing, redux thing or redux-form related? 它们是反应性事物,redux事物还是redux-form相关的? Where could I find documentation about them? 在哪里可以找到有关它们的文档? As those values are not something I'm by myself adding in anywhere. 由于这些价值不是我自己添加的任何内容。 I consoled them, and they consisted attributes like source and status: 我对它们进行了控制台,它们包含诸如源和状态之类的属性:

source: "FORM"
status: "RECEIVED"

Inside the render method of my component, I see no props.values. 在组件的render方法内部,没有看到props.values。 Only the props I have given to the component myself. 我只有自己给组件的道具。 But inside the shouldValidate function, there are props.values prop. 但是在shouldValidate函数内部,有props.values属性。

EDIT: For those trying to explain basics of props to me: 编辑:对于那些试图向我解释道具基础的人:

Do not, I know what props are in react. 不,我知道反应中有什么道具。 What I'm asking is what is this particular props.values prop? 我要问的是这个特殊的props.values属性是什么? Where does it come from, as I have not inserted it by myself. 它来自哪里,因为我自己还没有插入。 Somehow it is related to react, redux and redux-form 它以某种方式与react,redux和redux-form有关

Disclaimer: I'm one of the Redux Form maintainers. 免责声明:我是Redux Form维护者之一。

The shouldValidate function receives a single parameter params which is comprised of the following documented keys: shouldValidate函数接收单个参数params ,该参数params由以下记录的键组成:

  • values
  • nextProps
  • props
  • initialRender
  • structure

props / nextProps are a combination of props as documented here + whatever you manually provided to the component (eg <MyForm customProp="bla" /> ). props / nextProps这里记录的props以及您手动提供给组件的任何东西的组合(例如<MyForm customProp="bla" /> )。

Even though such prop values is available (and is in fact something from Redux Form), please don't rely on it. 即使提供了这些prop values (实际上是Redux Form中的值),也请不要依赖它。 As you can see, values is undocumented at that page. 如您所见,该页面上没有记录values

Also, there's no need to use something which is undocumented if the documented params of shouldValidate is equivalent. 另外,如果shouldValidate已记录params等效,则无需使用未记录的内容。

* If you feel like our docs could be improved to declare "special cased props", go ahead and send us a pull request! *如果您认为我们的文档可以改进以声明“特殊情况的道具”,请继续向我们发送拉取请求!

You linked the shouldValidate function documentation. 您链接了shouldValidate函数文档。 The documentation states that values are redux-form specific, and contains all the filed values your form currently has. 文档指出值是特定于redux格式的,并且包含您的表单当前具有的所有归档值。

Redux-form keeps track of all the input values you put inside a "Field" tag and keeps it in the redux store. Redux-form会跟踪您放置在“ Field”标签内的所有输入值,并将其保存在redux存储中。

The props are the properties you define for you own "Form" component. 道具是您为自己的“表单”组件定义的属性。 Redux-forms wraps it creating a HOC (higher order component). Redux-forms对其进行包装以创建HOC(高阶组件)。 It passes props in shouldValidate for you to access your props. 它在shouldValidate中传递道具,以供您访问道具。 props.values is an internal representation of filed values, which you should not rely on, the representation may change in the future. props.values是字段值的内部表示形式,您不应依赖它,该表示形式将来可能会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM