I've been making a web app using mern stack with babel, webpack, redux and semantic-ui-react.
But I got an error saying
"Unexpected token <" in bundle.js.
This error only occurs when I send a request clicking a button in form tag. If I make the page without a form tag, it works fine without any error.
This is my codes in React.
handleUpload(title, contents, userId) {
return this.props.createPostRequest(title, contents, userId).then(
() => {
if(this.props.post.status === 'SUCCESS') {
alert('Your post is saved successfully.');
browserHistory.push('/');
return true;
} else {
alert('Save Fail: ' + this.props.post.failReason);
return false;
}
}
);
}
render() {
return(
<div className="Write">
<br/>
<br/>
<Form>
<Container text>
<Form.Input label='Title' fluid name='title' placeholder='title'
value={this.state.title} onChange={this.handleChange}>
<input/>
</Form.Input>
<Form.TextArea rows='20' name='contents' placeholder='Write here!'
value={this.state.contents} onChange={this.handleChange}>
<textarea/>
</Form.TextArea>
<br/>
<Button.Group>
<Button color='orange' as={Link} to='/'>Cancel</Button>
<Button.Or/>
<Button positive onClick={this.handleUpload}>Save</Button>
</Button.Group>
</Container>
</Form>
</div>
);
}
When I type letters and click the save button, I can see an alert message saying
Your post is saved successfully..
And also the data I put is saved in mongodb. But after I click ok, the url changes from 'localhost:3000/post/write
' to 'localhost:3000/post/write?title=blah&contents=blah
'. blah in the url is what I put in input tags. Then console says
Unxpected token <.
But, if I don't use a form tag in above codes, it works fine, which I totally have no idea what's wrong about.. The Form tag is from semantic-ui-react. So I need it. If I don't use Form, it would work fine but I should give up the design provided from semantic-ui.
Is there anyone who knows about this? I guess it's related to the HTTP POST in form tags that make trouble for react.js to understand bundle.js in index.html after the server-side handles the post request from that form tag.