javascript - Not rendering this.props in render - react redux -
i try create react app. in basic make auth page login passport.js , express. tried display user mailadres, nothing seems work. this.props.email
header.jsx
import react, { component, proptypes } 'react'; import { connect } 'react-redux'; import * actions '../../reducers/auth/actions'; class header extends component { constructor(props) { super(props); this.props.getprofile(); } componentdidmount() { } logout() { this.props.signoutuser(); } render() { { <div> {this.props.username.emal} </div> ); } }; function mapstatetoprops(state) { return { username: state.auth.user }; } export default connect(mapstatetoprops, actions)(header);
my action file
import { push } 'react-router-redux' import { auth_user, auth_error, unauth_user, auth_user_profile } './types'; const jwt_decode = require('jwt-decode'); export function getprofile() { return dispatch => { return fetch('/user', { method: 'get', headers: { "content-type": "application/json", authorization: localstorage.getitem('token') } }).then(handleresponse) .then(data => { dispatch({ type: auth_user_profile, user: data }); return true; }).catch(err => dispatch(autherror("foutieve values"))); } }
and last item reducer file
import { auth_user, auth_error, unauth_user, auth_user_profile } './types'; export default function auth (state = { authenticated: false, admin_privileges: false, user: [] }, action) { switch (action.type) { case auth_user_profile: return { ...state, error: '', user: action.user.user, authenticated: true }; } return state; }
sorry alle code, think need see me out.
in this.props.username.emal
'email' spelled wrong.
also, this.props.getprofile()
should in componentdidmount()
, not in constructor, per docs
Comments
Post a Comment