pass URI.parseQuery value from default funtion to a user defined funtion

Viewed 31

I want to access user id and date from the url to function but because this is not the default class

http://localhost:3000/update?user=66&date=2022-06-27&tab=user

const getuserData = (props) => {
  
  console.log(props.user);
 console.log(props.date);
 
};

i have used useLocation

const Tracker = (props) => {
  const search = useLocation().search;

 console.log(URI.parseQuery(search));

console.log(URI.parseQuery(search)) is returning in cosole the following {user: '66', date: '2022-06-28', tab: 'diet'}

i want to pass user & date into getuserData

full code i have given in sandbox for refernce https://codesandbox.io/s/cool-lalande-87jbpq?file=/src/App.js

1 Answers

Try this and read Destructuring assignment for more info.

const getuserData = ({
  user,
  date
}) => {

  console.log(user);
  console.log(date);

};


const {
  search
} = useLocation();

getuserData(URI.parseQuery(search))

Related