my webpack config uses the main.jsx as entry component.(我的webpack配置使用main.jsx作为入口组件。)
This does all work as such and I call it like this:(这样就可以完成所有工作,我这样称呼它:)
<script src="./myApp.js"></script> <script> new myApp({ targetElem: document.querySelector('#order-form'), productData: ['test1', 'test2', 'test3'] }); </script>
What I want to achieve is, to use parameters that I provide, namely targetElem and productData(我要实现的是使用我提供的参数,即targetElem和productData)
The main.jsx looks like that and works perfectly:(main.jsx看起来像这样,并且运行良好:)
import React from 'react'; import { render } from 'react-dom'; import { HashRouter as Router, Route, Switch } from 'react-router-dom'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; import { persistStore } from 'redux-persist'; import { PersistGate } from 'redux-persist/integration/react'; import store from '../store'; import i18n from '../i18n'; import Start from './pages/start'; render( <Provider store={store}> <PersistGate loading={null} persistor={persistSt ore(store)}> <I18nextProvider i18n={i18n}> <Router> <Switch> <Route exact path="/" component={Start} /> </Switch> </Router> </I18nextProvider> </PersistGate> </Provider>, // Contextprovider does not work at the moment as they have an error there document.querySelector('#order-form') );
If I change it to this, to use the parameters:(如果将其更改为此,请使用参数:)
import React from 'react'; import { render } from 'react-dom'; import { HashRouter as Router, Route, Switch } from 'react-router-dom'; import { I18nextProvider } from 'react-i18next'; import { Provider } from 'react-redux'; import { persistStore } from 'redux-persist'; import { PersistGate } from 'redux-persist/integration/react'; import store from '../store'; import i18n from '../i18n'; import Start from './pages/start'; export default ({ productData, targetElem }) => { console.log(productData); render( <Provider store={store}> <PersistGate loading={null} persistor={persistStore(store)}> <I18nextProvider i18n={i18n}> <Router> <Switch> <Route exact path="/" component={Start} /> </Switch> </Router> </I18nextProvider> </PersistGate> </Provider>, // Contextprovider does not work at the moment as they have an error there targetElem ); };
The page stays white (and no errors in the console).(页面保持白色(控制台中没有错误)。) I have seen that it is definitely somehow possible.(我已经看到,这绝对是有可能的。) How to do it ?(怎么做 ?)
ask by Gutelaunetyp translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…