React HOC DOM 属性正在触发 'Unknown event handler property'

React HOC DOM properties are triggering 'Unknown event handler property'

我刚刚用 recompose 做了一个 HOC,但出于某种原因,所有传递下来的 props 都触发了 React 警告。

Warning: Unknown event handler property `onSaveChanges`. It will be ignored.

我所有的 属性 都具有相同的语法(从小写字母开始,然后是大写字母:lowerUpper)。当然,如果我把它写成完整的小写,那么它不会触发任何警告,但是如果我使用带有重构的 HOC,我是否应该将所有道具都写成小写?

我的 HOC:

import React from 'react'

import { withStateHandlers, withHandlers, withState, compose } from 'recompose'

const editableCell = (defaults) => 
    compose(
        withStateHandlers(
            { isEditing: false, value: ''},
            {
                toggleEditing: ({ isEditing, inputValue }) => defaultValue => ({
                    isEditing: true,
                    inputValue: isEditing ? inputValue : defaultValue
                }),
                onChange: () => event => ({
                    inputValue: event.target.value
                }),
                deactiveCell: () => () => ({
                    isEditing: false
                })
            }
        ),
        withHandlers({
            handleSave: ({
                isEditing,
                inputValue,
                onSaveChanges,
                deactiveCell,
            }) => event => {
                event.preventDefault()
                //can validate before save...
                deactiveCell()
                return onSaveChanges(isEditing, inputValue) 
            }
        })
    )

export default editableCell

基本上我的所有 属性 都会触发此警告(函数,或只是一个简单的原语,基本上任何东西 [isEditing、inputValue、onChange、deactivateCell、onSaveChanges、handleSave...等]

我该如何解决这个错误?真烦人。

问题与 Recompose 无关。根据the React doc:

The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as a legal DOM attribute/property. You should ensure that your DOM elements do not have spurious props floating around.

您应该只将有效的道具传递给 DOM 元素。例如:

不要

function MyDiv(props) {
  return <div {...props} />
}

function MyDiv({ onSaveChanges, inputValue, /** other invalid props **/, ...otherProps}) {
  return <div {...otherProps} />
}

the React doc中还有更多示例。