react material-ui textfield getting error: invalid hook call

℡╲_俬逩灬. 提交于 2021-01-29 09:14:31

问题


I have this simple code to show the text field:

I get the error

Error in /turbo_modules/react@16.13.0/cjs/react.development.js (1465:13) Invalid hook call.

The code is at this link https://stackblitz.com/edit/react-6dgvfj?file=UserForm.js

import React, { Component } from 'react';
import compose from 'recompose/compose';
import { connect } from 'react-redux';
import TextField from '@material-ui/core/TextField';

const UserForm = props => {
    return (
        <div>
            This is userform component.
            <TextField id="standard-basic" label="Standard" />

        </div>
    );
}

export default UserForm;

回答1:


react and react-dom packages always get released in pair. So they are bound to be of same release, to work together. In your case, react was of 16.12.0 and react-dom of 16.13.0

Your package.json

"dependencies": {
    "@material-ui/core": "^4.9.5",
    "@types/react": "^16.8.6",
    "react": "^16.13.0",
    "react-dom": "16.12.0"
  },

change it to

    "react": "16.13.0",
    "react-dom": "16.13.0"


来源:https://stackoverflow.com/questions/60647561/react-material-ui-textfield-getting-error-invalid-hook-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!