django-react-webpack
django-react-webpack copied to clipboard
how will one index.js will support mutliple pages
I downloaded the repo and ran
http://127.0.0.1:8000/polls/
its empty But i am expecting it to show "Hello world" as per the document.
index.js used for hello world.
import React from 'react'
import ReactDOM from 'react-dom'
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="world" />;
ReactDOM.render(
element,
document.getElementById('react')
);
when i go to url: http://127.0.0.1:8000/polls/questions/
it shows:
Questions
What's new?
this is as per the index.js
import React from 'react'
import ReactDOM from 'react-dom'
class Test extends React.Component {
render() {
var list = window.props;
return <div>{list.map(item => <TestChild key={item.pk}
question={item.question_text}/> )}</div>;
}
}
class TestChild extends React.Component {
render() {
return <li><b>{this.props.question}</b></li>;
}
}
ReactDOM.render(
<Test/>,
window.react_mount,
);
HOw to have multiple index.js files for each of urls.
Change
entry: './mysite/polls/static/js/index',
To
entry: {
main: './mysite/polls/static/js/index',
HomeApp: './mysite/polls/static/js/HomeApp',
},
in webpack.config.js and re-run npm run watch command for multiple page support