以下代码出现了 'React.Children.only expected to receive a single React element child.' 的错误提示信息。
我使用 create-react-app 创建了一个新的 React 应用程序,并安装了 redux 和 react-redux,创建了一个简单的 reducer 并使用它创建了一个 store。
import React from "react";
import ReactDOM from "react-dom";
import { createStore, combineReducers } from "redux";
import { Provider } from "react-redux";
import logo from './logo.svg';
import './App.css';
class App extends React.Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
</div>
);
}
}
function productReducer(state = [], action) {
return state;
}
const store = createStore(
productReducer
);
ReactDOM.render((<Provider store={store}><App /> </Provider>), document.getElementById('root'));