0
私のリアクションアプリケーションを作成しようとしています。基本的に私はpassport.jsでログインしてA Authページを作成し、明示します。私はユーザーのmailadresを表示するためにすべてを試みたが、何も動作していないようだ。 this.props.emailレンダリングでthis.propsをレンダリングしない - redux
Header.jsx
import React, {
Component,
PropTypes
} from 'react';
import {
connect
} from 'react-redux';
import * as actions from '../../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);
私のアクションファイル
import {
push
} from 'react-router-redux'
import {
AUTH_USER,
AUTH_ERROR,
UNAUTH_USER,
AUTH_USER_PROFILE
} from './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")));
}
}
そして最後の項目は私の減速ファイルです
ALLEコードのため申し訳ありませんimport {
AUTH_USER,
AUTH_ERROR,
UNAUTH_USER,
AUTH_USER_PROFILE
} from './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;
}
が、私はあなたが私を助けるためにすべてを見なければならないと思う。
ごとではなく、コンストラクタで、
componentDidMount()
であるべきか、減速の全てを組み合わせているところ? – RaghavGarg