v3.9.xからMUIv4.0.2にアップグレードした後、次のエラーが発生します。
connectによって返される関数にコンポーネントを渡す必要があります。代わりに、{"propTypes":{}、 "displayName": "WithStyles(MyComponent)"、 "options":{"defaultTheme":{"breakpoints":{"keys":["xs"、 "sm"、 "を受け取りましたmd "、" lg "、" xl "]、" values ":..。
MyComponent:
import { withStyles } from '@material-ui/core/styles'
const getStyles = theme => ({
fooBar: {
...
},
})
...
export default withStyles(getStyles)(MyComponent)
MyContainer:
import { connect } from 'react-redux'
import MyComponent from './MyComponent'
...
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)
移行する方法はwithStyles
?
react-reduxのバージョン5.0.7以前は、渡されたコンポーネントに対して次の検証を実行しましたconnect
。
https://github.com/reduxjs/react-redux/blob/v5.0.7/src/components/connectAdvanced.js#L91
invariant(
typeof WrappedComponent == 'function',
`You must pass a component to the function returned by ` +
`${methodName}. Instead received ${JSON.stringify(WrappedComponent)}`
)
導入によりReact.forwardRef
、および16.8(フック)と反応で導入された他の特徴(材料-UIのV4に頻繁に使用されている)、コンポーネントタイプ有することが可能でない機能を。
最新バージョンのreact-reduxは、代わりにパッケージのisValidElementTypeを使用しreact-is
ます。これによりforwardRef
、および他のメソッドによって返されるコンポーネントタイプが正しく認識されます。
私は、react-reduxのバージョン5.1以降は、質問に記載されているエラーを誤って引き起こすことなく、すべて正常に機能するはずだと信じています。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加