私はtitle, description, old price
とnew price
のレンダリングが必要なAPIを持っていますが、正しい方法を知りません。react.jsのAPIを使用してデータをレンダリングしますか?
ここで私は私が間違った方法でデータを取得していると思う私のAPI
export class Content extends React.Component{
constructor(){
super();
this.state={};
}
componentWillMount(){
var url="95.85.23.63:8000/frontend/web/api/v1/user/get-popular";
Request.get(url).then((reponse)=>{
this.setState({
infos:response.body.Search,
total:response.body.totalResults
});
});
}
render(){
var infos=_.map(this.state.infos, (info)=>{
return <li>{info.title}</li>;
});
return(
<div>
<ul> {infos}</ul>
</div>
)
}
}
とコンテンツコンポーネント。手伝っていただけませんか?
に要求するために推奨されるか、あなたが反応し使用することができ、次のコードを参照してください。 -thunkまたはreact-sagaを使用してapiからデータを取得します。コンポーネントがマウントされているときは、componentDidMount(){this.props.dispatch(search)}} –