0
반응 애플리케이션을 만들려고합니다. 기본에서는 passport.js로 로그인하여 A Auth 페이지를 만들고 표현합니다. 나는 사용자 mailadres를 표시하기 위해 모든 것을 시도했지만 아무것도 작동하지 않는 것 같습니다.렌더링에서 this.props 렌더링 - reactx
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;
}
미안 내 감속기 파일입니다 this.props.email하지만, 나는 너를 도와 나를 도울 필요가 있다고 생각해.
당이 아닌 생성자에서,
componentDidMount()
에 있어야하거나 감속기의 모든 결합되는 곳 ? – RaghavGarg