how do we use redux with react-router or should we use redux-router-first-link?
i have my components
Signup
import React, { Component } from "react";
import { connect } from "react-redux";
import * as actionCreators from "./Store/Actions/Actions";
import { withRouter } from "react-router-dom";
class Signup extends Component {
render() {
console.log("signup is mounted");
return (
<div>
<header>Signup component</header>
<button onClick={this.props.onIncrementCounter}>Increment</button> */}
<div value={this.props.ctr}>counter:</div>
</div>
);
}
}
const mapStateToProps = state => {
return {
ctr: state.counter
};
};
const mapDispatchToProps = dispatch => {
return {
onIncrementCounter: () => dispatch(actionCreators.increment()),
onDecrementCounter: () => dispatch(actionCreators.decrement()),
onResetCounter: () => dispatch(actionCreators.reset())
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Signup)
);
and main
import React, { Component } from "react";
import Link from "redux-first-router-link";
import Dashboard from "./Dashboard";
import Signup from "./Signup";
import Login from "./Login";
class Main extends Component {
render() {
console.log("main component");
return (
<div>
<header>
<Link to="/users/signup">
<button>Signup</button>
</Link>
<Link to="/users/login">Login</Link>
<Link to="/dashboard">Dashboard</Link>
Main component
</header>
</div>
);
}
}
export default Main;
and my app component
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Dashboard from "./Dashboard";
import { Provider } from "react-redux";
import Signup from "./Signup";
import Login from "./Login";
import Main from "./Main";
const App = ({ store }) => (
<Provider store={store}>
<Router>
<div>
<Route path="/" component={Main} />
<Route path="/users/login" component={Login} />
<Route path="/users/signup" component={Signup} />
</div>
</Router>
</Provider>
);
export default App;
and index file
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import Reducer from "./Store/Reducers/reducer";
import { createStore } from "redux";
import { Provider } from "react-redux";
const store = createStore(Reducer);
// ReactDOM.render(<App store={store} />, document.getElementById("root"));
ReactDOM.render(
<App store={store} />,
document.getElementById("root")
);
serviceWorker.unregister();
and reducer
import * as actionTypes from "../Actions/ActionTypes";
const initialState = {
counter: 0
};
export const Reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.INCREMENT:
return {
...state,
counter: state.counter + 1
};
case actionTypes.RESET:
return {
...state,
counter: state.counter
};
case actionTypes.DECREMENT:
return {
...state,
counter: state.counter - 1
};
}
};
export default Reducer;
and actions file
import * as actionTypes from "./ActionTypes";
export const increment = () => {
return {
type: actionTypes.INCREMENT
};
};
export const decrement = () => {
return {
type: actionTypes.DECREMENT
};
};
export const reset = () => {
console.log(actionTypes.RESET);
return {
type: actionTypes.RESET
};
};
but i am getting these errors:
The above error occurred in the component:
Uncaught TypeError: _selectLocationState is not a function
how do I integrate this react-router with redux? I think >there is an error connecting react-router with redux.
Should I use React-router-redux or integrate with react-router and redux?
I want to navigate to signup component from main component and render value of counter to be incremented with a button, and the same value should be reflected in login component also (where i want to decrement counter value and this should again reflect in signup)
html5 redux react-redux react-router redux-saga
add a comment |
i have my components
Signup
import React, { Component } from "react";
import { connect } from "react-redux";
import * as actionCreators from "./Store/Actions/Actions";
import { withRouter } from "react-router-dom";
class Signup extends Component {
render() {
console.log("signup is mounted");
return (
<div>
<header>Signup component</header>
<button onClick={this.props.onIncrementCounter}>Increment</button> */}
<div value={this.props.ctr}>counter:</div>
</div>
);
}
}
const mapStateToProps = state => {
return {
ctr: state.counter
};
};
const mapDispatchToProps = dispatch => {
return {
onIncrementCounter: () => dispatch(actionCreators.increment()),
onDecrementCounter: () => dispatch(actionCreators.decrement()),
onResetCounter: () => dispatch(actionCreators.reset())
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Signup)
);
and main
import React, { Component } from "react";
import Link from "redux-first-router-link";
import Dashboard from "./Dashboard";
import Signup from "./Signup";
import Login from "./Login";
class Main extends Component {
render() {
console.log("main component");
return (
<div>
<header>
<Link to="/users/signup">
<button>Signup</button>
</Link>
<Link to="/users/login">Login</Link>
<Link to="/dashboard">Dashboard</Link>
Main component
</header>
</div>
);
}
}
export default Main;
and my app component
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Dashboard from "./Dashboard";
import { Provider } from "react-redux";
import Signup from "./Signup";
import Login from "./Login";
import Main from "./Main";
const App = ({ store }) => (
<Provider store={store}>
<Router>
<div>
<Route path="/" component={Main} />
<Route path="/users/login" component={Login} />
<Route path="/users/signup" component={Signup} />
</div>
</Router>
</Provider>
);
export default App;
and index file
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import Reducer from "./Store/Reducers/reducer";
import { createStore } from "redux";
import { Provider } from "react-redux";
const store = createStore(Reducer);
// ReactDOM.render(<App store={store} />, document.getElementById("root"));
ReactDOM.render(
<App store={store} />,
document.getElementById("root")
);
serviceWorker.unregister();
and reducer
import * as actionTypes from "../Actions/ActionTypes";
const initialState = {
counter: 0
};
export const Reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.INCREMENT:
return {
...state,
counter: state.counter + 1
};
case actionTypes.RESET:
return {
...state,
counter: state.counter
};
case actionTypes.DECREMENT:
return {
...state,
counter: state.counter - 1
};
}
};
export default Reducer;
and actions file
import * as actionTypes from "./ActionTypes";
export const increment = () => {
return {
type: actionTypes.INCREMENT
};
};
export const decrement = () => {
return {
type: actionTypes.DECREMENT
};
};
export const reset = () => {
console.log(actionTypes.RESET);
return {
type: actionTypes.RESET
};
};
but i am getting these errors:
The above error occurred in the component:
Uncaught TypeError: _selectLocationState is not a function
how do I integrate this react-router with redux? I think >there is an error connecting react-router with redux.
Should I use React-router-redux or integrate with react-router and redux?
I want to navigate to signup component from main component and render value of counter to be incremented with a button, and the same value should be reflected in login component also (where i want to decrement counter value and this should again reflect in signup)
html5 redux react-redux react-router redux-saga
I am not sure if you can useredux-first-router-link
together withreact-router
. You should probably use eitherredux-first-router
+redux-first-router-link
or just importLink
fromreact-router-dom
instead.
– Martin Kadlec
Dec 29 '18 at 15:16
add a comment |
i have my components
Signup
import React, { Component } from "react";
import { connect } from "react-redux";
import * as actionCreators from "./Store/Actions/Actions";
import { withRouter } from "react-router-dom";
class Signup extends Component {
render() {
console.log("signup is mounted");
return (
<div>
<header>Signup component</header>
<button onClick={this.props.onIncrementCounter}>Increment</button> */}
<div value={this.props.ctr}>counter:</div>
</div>
);
}
}
const mapStateToProps = state => {
return {
ctr: state.counter
};
};
const mapDispatchToProps = dispatch => {
return {
onIncrementCounter: () => dispatch(actionCreators.increment()),
onDecrementCounter: () => dispatch(actionCreators.decrement()),
onResetCounter: () => dispatch(actionCreators.reset())
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Signup)
);
and main
import React, { Component } from "react";
import Link from "redux-first-router-link";
import Dashboard from "./Dashboard";
import Signup from "./Signup";
import Login from "./Login";
class Main extends Component {
render() {
console.log("main component");
return (
<div>
<header>
<Link to="/users/signup">
<button>Signup</button>
</Link>
<Link to="/users/login">Login</Link>
<Link to="/dashboard">Dashboard</Link>
Main component
</header>
</div>
);
}
}
export default Main;
and my app component
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Dashboard from "./Dashboard";
import { Provider } from "react-redux";
import Signup from "./Signup";
import Login from "./Login";
import Main from "./Main";
const App = ({ store }) => (
<Provider store={store}>
<Router>
<div>
<Route path="/" component={Main} />
<Route path="/users/login" component={Login} />
<Route path="/users/signup" component={Signup} />
</div>
</Router>
</Provider>
);
export default App;
and index file
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import Reducer from "./Store/Reducers/reducer";
import { createStore } from "redux";
import { Provider } from "react-redux";
const store = createStore(Reducer);
// ReactDOM.render(<App store={store} />, document.getElementById("root"));
ReactDOM.render(
<App store={store} />,
document.getElementById("root")
);
serviceWorker.unregister();
and reducer
import * as actionTypes from "../Actions/ActionTypes";
const initialState = {
counter: 0
};
export const Reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.INCREMENT:
return {
...state,
counter: state.counter + 1
};
case actionTypes.RESET:
return {
...state,
counter: state.counter
};
case actionTypes.DECREMENT:
return {
...state,
counter: state.counter - 1
};
}
};
export default Reducer;
and actions file
import * as actionTypes from "./ActionTypes";
export const increment = () => {
return {
type: actionTypes.INCREMENT
};
};
export const decrement = () => {
return {
type: actionTypes.DECREMENT
};
};
export const reset = () => {
console.log(actionTypes.RESET);
return {
type: actionTypes.RESET
};
};
but i am getting these errors:
The above error occurred in the component:
Uncaught TypeError: _selectLocationState is not a function
how do I integrate this react-router with redux? I think >there is an error connecting react-router with redux.
Should I use React-router-redux or integrate with react-router and redux?
I want to navigate to signup component from main component and render value of counter to be incremented with a button, and the same value should be reflected in login component also (where i want to decrement counter value and this should again reflect in signup)
html5 redux react-redux react-router redux-saga
i have my components
Signup
import React, { Component } from "react";
import { connect } from "react-redux";
import * as actionCreators from "./Store/Actions/Actions";
import { withRouter } from "react-router-dom";
class Signup extends Component {
render() {
console.log("signup is mounted");
return (
<div>
<header>Signup component</header>
<button onClick={this.props.onIncrementCounter}>Increment</button> */}
<div value={this.props.ctr}>counter:</div>
</div>
);
}
}
const mapStateToProps = state => {
return {
ctr: state.counter
};
};
const mapDispatchToProps = dispatch => {
return {
onIncrementCounter: () => dispatch(actionCreators.increment()),
onDecrementCounter: () => dispatch(actionCreators.decrement()),
onResetCounter: () => dispatch(actionCreators.reset())
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(Signup)
);
and main
import React, { Component } from "react";
import Link from "redux-first-router-link";
import Dashboard from "./Dashboard";
import Signup from "./Signup";
import Login from "./Login";
class Main extends Component {
render() {
console.log("main component");
return (
<div>
<header>
<Link to="/users/signup">
<button>Signup</button>
</Link>
<Link to="/users/login">Login</Link>
<Link to="/dashboard">Dashboard</Link>
Main component
</header>
</div>
);
}
}
export default Main;
and my app component
import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Dashboard from "./Dashboard";
import { Provider } from "react-redux";
import Signup from "./Signup";
import Login from "./Login";
import Main from "./Main";
const App = ({ store }) => (
<Provider store={store}>
<Router>
<div>
<Route path="/" component={Main} />
<Route path="/users/login" component={Login} />
<Route path="/users/signup" component={Signup} />
</div>
</Router>
</Provider>
);
export default App;
and index file
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import Reducer from "./Store/Reducers/reducer";
import { createStore } from "redux";
import { Provider } from "react-redux";
const store = createStore(Reducer);
// ReactDOM.render(<App store={store} />, document.getElementById("root"));
ReactDOM.render(
<App store={store} />,
document.getElementById("root")
);
serviceWorker.unregister();
and reducer
import * as actionTypes from "../Actions/ActionTypes";
const initialState = {
counter: 0
};
export const Reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.INCREMENT:
return {
...state,
counter: state.counter + 1
};
case actionTypes.RESET:
return {
...state,
counter: state.counter
};
case actionTypes.DECREMENT:
return {
...state,
counter: state.counter - 1
};
}
};
export default Reducer;
and actions file
import * as actionTypes from "./ActionTypes";
export const increment = () => {
return {
type: actionTypes.INCREMENT
};
};
export const decrement = () => {
return {
type: actionTypes.DECREMENT
};
};
export const reset = () => {
console.log(actionTypes.RESET);
return {
type: actionTypes.RESET
};
};
but i am getting these errors:
The above error occurred in the component:
Uncaught TypeError: _selectLocationState is not a function
how do I integrate this react-router with redux? I think >there is an error connecting react-router with redux.
Should I use React-router-redux or integrate with react-router and redux?
I want to navigate to signup component from main component and render value of counter to be incremented with a button, and the same value should be reflected in login component also (where i want to decrement counter value and this should again reflect in signup)
html5 redux react-redux react-router redux-saga
html5 redux react-redux react-router redux-saga
edited Dec 29 '18 at 15:11


James Z
11.1k71835
11.1k71835
asked Dec 29 '18 at 13:08


Prathima SeethalamPrathima Seethalam
1
1
I am not sure if you can useredux-first-router-link
together withreact-router
. You should probably use eitherredux-first-router
+redux-first-router-link
or just importLink
fromreact-router-dom
instead.
– Martin Kadlec
Dec 29 '18 at 15:16
add a comment |
I am not sure if you can useredux-first-router-link
together withreact-router
. You should probably use eitherredux-first-router
+redux-first-router-link
or just importLink
fromreact-router-dom
instead.
– Martin Kadlec
Dec 29 '18 at 15:16
I am not sure if you can use
redux-first-router-link
together with react-router
. You should probably use either redux-first-router
+ redux-first-router-link
or just import Link
from react-router-dom
instead.– Martin Kadlec
Dec 29 '18 at 15:16
I am not sure if you can use
redux-first-router-link
together with react-router
. You should probably use either redux-first-router
+ redux-first-router-link
or just import Link
from react-router-dom
instead.– Martin Kadlec
Dec 29 '18 at 15:16
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969837%2fhow-do-we-use-redux-with-react-router-or-should-we-use-redux-router-first-link%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969837%2fhow-do-we-use-redux-with-react-router-or-should-we-use-redux-router-first-link%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I am not sure if you can use
redux-first-router-link
together withreact-router
. You should probably use eitherredux-first-router
+redux-first-router-link
or just importLink
fromreact-router-dom
instead.– Martin Kadlec
Dec 29 '18 at 15:16