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

How to use a react hook in an arrow function?

$
0
0

I'm designing an application in react native for medical use case. The idea is to record some audio and to send it to a local server. Therefore, the ip adress is defined at runtime.

Previously, I used a global const as adress (code below).

const url = 'http://192.168.43.56:5000/';const checkIsServerOnline = async (): Promise<string> =>  axios.get(url, {    timeout: 5000,  });

Now I would like to retrieve the url from a redux (persistant) store before using the function. I tried something like that, but it didn't worked:

function CheckIsServerOnline(): AxiosPromise {  const { ipAdress } = useSelector(    (state: RootState) => state.config  );  return axios.get(ipAdress, {    timeout: 5000,  });}

The error message it returned:

Invalid hook call. Hooks can only be called inside of the body of afunction component. This could happen for one of the followingreasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app

Do you have any idea how I would be able to retrieve the value from the redux state ?

(Apologies for the begineer question)


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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