J
J
jww2017-09-07 21:46:08
JavaScript
jww, 2017-09-07 21:46:08

Where can I see an example code for a React component interacting with the API?

Good day. I am studying the React - Redux connection, I would like to see an example of a simple component that would interact with some kind of API. Please post such an example.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
kulaeff, 2017-09-07
@kulaeff

Are you sure you phrased the question correctly? After all, the component should not (but can) interact with the API. He should not know anything about the API at all.

I
Ilya Gerasimov, 2017-09-07
@Omashu

Who knows what the "rules" are now, everything changes too often, but the last time I looked at this topic there was something in the spirit of smart containers and stupid components, containers communicate with api, change the redax state, local state, based on this state stupid components work. But in fact, you can communicate with the API how and where you want, and over time, you will most likely encounter certain problems yourself, code duplication or something like that and understand how to fix it (yourself), you will understand that you need to google, studying the topic not you must immediately try to make the ideal, especially since this concept is different for everyone.

I
Islam Ibakaev, 2017-09-08
@devellopah

ideally the component doesn't "interact" with the api.
if you use redux-thunk, then the api request is made by the operator (action creator), while the container itself just pulls this operator in the componentDidMount method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question