redux

why my redux state not updating

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:09:25
问题 state not updating.when action is dispatched the state should update to isAuthenticated to true..but the state not updating..redux returning the initial state not the updated state. export function setCurrentUser(user) { console.log(user); return { type: "SET_CURRENT_USER", user }; } ... export function login(userData) { return dispatch => { return axios.post('/user/auth',userData).then((res) => { const { status, sessionId, username, error} = res.data; if(status === "success"){ dispatch

Where do I update the location after an async dispatch with react-router and redux

时光毁灭记忆、已成空白 提交于 2019-12-12 01:43:14
问题 The problem I have now is that I don't know how to get my location to update after "FETCH_USER_FULFILLED" was dispatched (see https://github.com/DDecoene/React-flux-example/blob/4ab1503dc92d28108f50481a293104ba5d15a29e/app/actions/userActions.js#L17) What I'm trying to do, is to do a post to an API and when it is OK, switch to the index 'page' I've tried redux-router too but I did not get it to work at all. 回答1: I would suggest using react-router-redux. It comes with push and replace actions

How to access json file in src folder created using create react app

岁酱吖の 提交于 2019-12-12 01:15:09
问题 I'm a newbie to react. I have created react application using npx create-react-app. In actions,axios.get is throwing localhost:3000 file not found error. Below is the code which is in src/actions/index.js export function lang(language) { let url = "./../resources/strings/strings_" + language + ".json"; return dispatch => { axios.get(url).then(response => { console.log(response.data) }).catch(response => { console.log(response); }); } } This is the project structure [1]: https://i.stack.imgur

Generic TypeScript Type for functions returning functions that replaces the ReturnType with the ReturnType of the returned function

我与影子孤独终老i 提交于 2019-12-12 01:03:29
问题 Dear TypeScript-3-Gurus out there, can someone help my define a generic type GuruMagic<T> that does the following? T is a function returning a function, e.g. this: fetchUser(id: Id) => (dispatch: Dispatch) => Promise<boolean> The generic type should then replace the ReturnType of fetchUser with the ReturnType of the returned function. Like this: type dispatchedAction = GuruMagic<typeof fetchUser>; // so that dispatchedAction === (id: Id) => Promise<boolean> I know that I can apply ReturnType

React redux async action creator test

て烟熏妆下的殇ゞ 提交于 2019-12-11 19:49:21
问题 I am new to the react redux. I am trying to test the async action action looks like > export function fetchUserJd() { return (dispatch) => { let url = FETCH_JD_ROOT_URL + page + "&" + size; dispatch({ type: REQUEST_INITIATED }) get(url) .then((response) => { if (response.status === 200) { dispatch({ type: REQUEST_SUCCESSED, }); dispatch({ type: FETCHING_JOBDESCRIPTION_SUCCESS, data: response.payload, } ) } else { dispatch({ type: REQUEST_SUCCESSED }) toastr.error("Error while fetching Job

Updating a selected object when user changes inputs in a form

我们两清 提交于 2019-12-11 19:06:20
问题 When a user clicks a square it becomes currentHtmlObject . I want people to be able to update it's properties in the right sidebar. I have no idea how to take a single input field and update an object's property that I'm holding in a react-redux state and update the main viewing area DrawingCanvas . I got kinda close where the info I was entering into the form was activating my reducers and actions. But I couldn't figure out how to distinguish between left and top . // React import React from

Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`

杀马特。学长 韩版系。学妹 提交于 2019-12-11 18:49:03
问题 This is my code: My container: import {connect} from 'react-redux'; import UI from '../../ui/studentRegistrationUI/RegisterFormUI' import {beginRegistration, setLevel} from "../../../../actions"; const mapStateToProps = state => ({user: state.user}); const mapDispatchToProps = dispatch => ({ handleClick() { dispatch(beginRegistration('student')); } }); export default connect(mapStateToProps, mapDispatchToProps)(UI) My UI component: //imports export default (handleClick = f => f) => ( <div

How one can copy/paste a route and get the 'right' page using React-router?

荒凉一梦 提交于 2019-12-11 18:21:51
问题 Routing is implemented on client and looks something like: <Provider store={ store }> <Router history={ browserHistory }> <Route path="/" component={ Layout }> <IndexRoute component={ Tracking }></IndexRoute> <Route path="users" component={ UserTable }></Route> <Route path="user/:login" component={ UserPage }></Route></Route> </Route> </Router> </Provider> Server-side router looks something like: app.get('/', checkAuthStatus, redirect.index); app.get('*', redirect.UndefinedRoutes); The

this.props.children.map at react native is not working

左心房为你撑大大i 提交于 2019-12-11 17:58:57
问题 I want to render a child component from a parent component by passing to it one object from array of objects fetched from an api. TypeError: this.props.posts.map is not a function renderPosts() { return this.props.posts.map(post => <HomeCard key={post.id} postData={post} /> ); } All the component: class Home extends Component { componentWillMount() { this.props.getUserPosts(); } renderPosts() { return this.props.posts.map(post => <HomeCard key={post.id} postData={post} /> ); } render() {

Navbar with dynamic content and behaviour

扶醉桌前 提交于 2019-12-11 17:58:36
问题 Say I have the following App.js : App.js render() { return ( <div> <Navbar /> <Router> <Home path="/" /> <RouteA path="/routeA" /> <RouteB path="/routeB" /> </Router> </div> ); } So I need the <Navbar /> to behave and look differently in the /routeA and /routeB . For example, there is a back button in the <Navbar /> . And when user is in /routeA , clicking the back btn will go back one step in history. However, when user is in /routeB , not only that clicking back btn will now pops up an