Manual submit causes page refresh and wrong routing
See original GitHub issueusing enter to submit works fine, but triggering onClick will refresh the page and for some reason tries to access (relative url)?searchSymbol={searchSymbol}. i dont think wad.
import * as React from 'react';
import * as StockActions from '../redux/actions/stock';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Field, reduxForm, submit } from 'redux-form';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { RootState } from '../redux/reducers';
import { Row, Load } from '.';
const searchStyle = require('../assets/_searchbutton.css');
export namespace SearchButton {
export interface Props {
actions: typeof StockActions
history: any
handleSubmit: any
serachSymbol: string
}
export interface State { }
}
class SearchButton extends React.Component<SearchButton.Props, SearchButton.State> {
renderField = props => (
<input type={props.type} {...props.input} />
)
handleFormSubmit(props) {
//this.props.history.push(`/stock/${props.searchSymbol}`)
}
handleSearchSubmit() {
(this.refs.searchButtonForm as any).submit()
}
render() {
const { handleSubmit } = this.props;
return (
<li className="search-button">
<form ref="searchButtonForm" onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
<Field name='searchSymbol' type='text' placeholder='Symbol' component={this.renderField} />
<a onClick={() => {
this.handleSearchSubmit()
}}>
<span className='search-icon' />
</a>
</form>
</li>
);
}
}
function mapStateToProps(state: RootState) {
return {
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(StockActions as any, dispatch)
};
}
function validate(values) {
const errors: { searchSymbol?: string } = {}
if (!values.searchSymbol || values.searchSymbol.length == 0) {
errors.searchSymbol = 'symbol may not be empty'
}
return errors;
}
export default withRouter(connect<any, any, any>(mapStateToProps, mapDispatchToProps)(reduxForm({ form: 'searchButtonForm', validate })(SearchButton)));
What’s your environment?
6.6.3, firefox, node 6.9.3
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
React-router URLs don't work when refreshing or writing ...
The historyApiFallback is what fixed this issue for me. Now routing works correctly and I can refresh the page or type in the...
Read more >5.x: POST to create causes URL change even if form errors ...
I fill out the form but omit a required field, and then click submit. The url changes to /users but rails will render...
Read more >How to prevent browser refresh, URL changes, or route ...
How to prevent browser refresh, URL changes, or route navigation in Vue · Prevent URL change and/or page reload. · Prevent router navigation....
Read more >How to Refresh a Page or Component in React - Upmostly
The first way of refreshing a page or component is to use vanilla JavaScript to call the reload method to tell the browser...
Read more >Angular: Reload/Refresh a Component or Entire Application ...
First I click on Reload Current Route button. As you can see in the console, navigation has succeeded but the AppComponent has not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Because I’m struggling with React and all it’s libraries and I’m not proficient at technical writing at all. I’m pretty happy right now to not have to think about redux-router. You think someone who writes an issue like this would make a good contributor? Plus I wrote this when I spend some hours on redux-form problems again; it may not just be my own opinion, but a biased one as well.
totally getting the spirit of OSS there