0

https://obikes.page.link/d6o5/?ref=10959bc I am using axios this is my invite link in my app i want to get data after query string i need ref code ref=10959bc ,how can i get this query data 10959bc in react native i am unable to find any solution

React.useEffect(async () => {
    const getValue = await AsyncStorage.getItem('token');
    
    await getReferal().then(response => {
      console.log(response.data.refferalUrl); //https://obikes.page.link/d6o5/?ref=10959bc
      //  refer code 
  
    })
    .catch(error => {
      console.log(error);
    });
1
  • Your question isn't clear, you want to get the query paramters of the response? Commented Jul 7, 2021 at 10:23

2 Answers 2

1

A pure JS approach:

React.useEffect(async () => {
    const getValue = await AsyncStorage.getItem('token');
    
    await getReferal().then(response => {
        console.log(response.data.refferalUrl);
        // refer code:
        const url = response.data.refferalUrl
        let regex = /[?&]([^=#]+)=([^&#]*)/g, params = {}, match;
        while ((match = regex.exec(url))) {
            params[match[1]] = match[2];
        }
        console.log(params) // => {ref: "10959bc"}  
    })
    .catch(error => {
      console.log(error);
    });
Sign up to request clarification or add additional context in comments.

Comments

0

Use the qs npm package to get the query string params from a string.

https://github.com/ljharb/qs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.