redux 양식을 사용하여 해당 필드 결과가있는 API를 조회하는 작업 작성자에게 필드를 전달하려고합니다. 결과는 동일한 구성 요소로 다시 보내 져야하며 검색 입력 필드 아래에 렌더링되어야합니다. 여기 여기 내 행동 작성자내 redux 양식 결과가 동일한 구성 요소 내에서 렌더링되도록 시도하십시오.
export function getStock({ticker_symbol}){
console.log(ticker_symbol)
return function(dispatch) {
axios.get(`https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=${ticker_symbol}&interval=1min&apikey=5QP2C2R2YCZ71HDB&datatype=json`, {
headers: { authorization: localStorage.getItem('token')}
})
.then(res => {
console.log(res.data["Time Series (1min)"])
dispatch({
type: GET_STOCK,
payload: res.data
})
}).catch(res => {
dispatch(authError(res.error))
});
}
}
여기 감속기
import {
FETCH_MESSAGE,
GET_STOCK
} from '../actions/types';
export default function(state = {}, action){
switch(action.type) {
case FETCH_MESSAGE:
return {...state, message: action.payload};
case GET_STOCK:
return {...state, stock: action.payload,
stockDataLoaded: false};
}
return state;
}
인 형태를 가지고 있으며, 렌더링 정보를 얻을 수 있다고 가정하는 구성 요소입니다. 콘솔 로그가 올바른 데이터를 가져옵니다. 여기
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { reduxForm } from 'redux-form';
import * as actions from '../actions';
class Feature extends Component{
componentWillMount(){
this.props.fetchMessage();
}
handleFormSubmit({ ticker_symbol }){
console.log(ticker_symbol);
this.props.getStock({ticker_symbol});
}
render(){
const { handleSubmit, fields: { ticker_symbol }} = this.props;
return (
<div>
<form onSubmit={ handleSubmit(this.handleFormSubmit.bind(this))}>
<fieldset className="form-group">
<label> Ticker Symbol: </label>
<input {...ticker_symbol} className="form-control" />
</fieldset>
<button action="submit" className="btn btn-primary"> Get Quote </button>
</form>
<h1></h1>
</div>
);
}
}
function mapStateToProps(state){
console.log(state);
return { message: state.stock.message,
stock: state.stock.stock};
}
export default reduxForm({
form: 'getstock',
fields: ['ticker_symbol']
}, mapStateToProps, actions)(Feature);
는
나는 결과가 댓글에 응답 종목 기호
이 모든 것이 잘 보입니다. 어떤 문제가 있습니까? – gravityplanx
구성 요소의 빈
태그에 state.state.stock을 넣으려고 할 때마다 오류가 발생합니다. 결과가 돌아올 때까지 아무 상태도 없기 때문에 나는 추측한다. 나는 약간 새로운 것, 확실하지 않다. – jdip88