当尝试在Material UI的0.16.6版本中使用AppBar时,我收到以下错误
Uncaught Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded.
看起来像是反应冲突错误。
我的代码如下:
App.js
import React, { Component } from 'react';
import AppBar from 'material-ui/AppBar';
import {deepOrange500} from 'material-ui/styles/colors';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
const muiTheme = getMuiTheme({
palette: {
accent1Color: deepOrange500,
},
});
class App extends Component {
render() {
return (
<MuiThemeProvider muiTheme={muiTheme}>
<AppBar/>
</MuiThemeProvider>
);
}
}
export default App;
index.js
import injectTapEventPlugin from 'react-tap-event-plugin';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<App />,
document.getElementById('root')
);
是否有人遇到此问题,或者有人知道如何解决问题吗?
答案 0 :(得分:1)
在index.js
文件中,您需要在ReactDOM.render
来电之前:
// Needed for onTouchTap event handling
injectTapEventPlugin();
看看是否能解决问题。如果没有,请尝试删除node_modules
文件夹并再次运行npm install
。