I want to set the routes for my web app using Express, and I'm also using React to handle the front end. The problem is that I don't understand how to route things properly when using React components.
I have in my index.html:
<script> document.getElementById("input").onchange = function() { ... } </script>
And my App.js:
class App extends Component {
render() {
return ( <div><input id="input" /></div> );
}
}
And router.js:
app.get('/', function (req, res) {
res.sendFile(path.resolve('public/index.html'))
})
app.use(express.static('static'));
app.listen(3001, function () {
console.log('Example app listening on port 3001!')
})
And static/index.js:
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
The problem is that I'm getting "Cannot set property 'onchange' of null". Obviously the App object was not rendered, but I don't understand why. How can I make this work?