gpt4 book ai didi

javascript - 将 redux-react 与 react-router 一起使用时无效的 prop 'component'

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:00 26 4
gpt4 key购买 nike

在我的例子中,当使用来自 react-redux 的 connect 时,react router 没有将我的 react 组件视为有效组件。并且有一个警告:Failed propType: Invalid prop component supplied to Route

index.js

import { connect } from 'react-redux'
import { createStore } from 'redux'
import { Provider } from 'react-redux'
import plattformApp from './reducers'

var React = require('react');
var ReactDOM = require('react-dom');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var hashHistory = ReactRouter.hashHistory;
var Main = require('./components/Main');

let store = createStore(plattformApp)

ReactDOM.render(
<Provider store={store}>
<Router history={hashHistory}>
<Route path='/' component={Main}>
</Route>
</Router>
</Provider>,
document.getElementById('app')
)

Main.js

var React = require('react');
var ReactRouter = require('react-router');
var Link = ReactRouter.Link;
var KNGui = require("../components/KNGui");
var Search = require("../components/Search");

var Main = React.createClass({
render: function () {
return (
<div>
</div>
)
}
});

function mapStateToProps(state) {
return { test: state }
}

export default connect(mapStateToProps)(Main)

最佳答案

现在 var Main 包含完整的模块。

要访问您需要的组件

var Main = require('./components/Main').default;

import Main from './components/Main';

获取组件。

关于javascript - 将 redux-react 与 react-router 一起使用时无效的 prop 'component',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38351975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com