Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to set state of the response to an api call for a complex object to react context in order to not have to make api call again?

$
0
0

I'm working on a react native typescript project.

How do I set my context object to the data I receive as a response from an api call?

I don't want to have to make the API call every time I load the component?So I want to check the context if it's there , don't make the call.

I see a lot of examples , but none seem to set the state without a function. I just want to be set the context to a new context object. Even if state never changes.

Just set context to a new context then when the component loads again, don't make the API call because the context is already set.

Looking for a hook based example or class based example, preferably hooks.

The documentation either shows just how to pass the context or just how to set the state with a function. I want to simply set the context to be whatever I originally requested for.

The object itself is a Location[] with strings such as name, address, city , state , zip, phone etc so there may be multiple Locations.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>