728x90

Params 사용법

 

Navigate 의 속성이며 paramse : {ㅌㅌㅌㅌㅌㅌ : ㅌㅌㅌㅌㅌ} 로 보내준다

 

<MovieWrapper onPress={() => navigate('Stacks', { screen: 'Detail', params: { movieId: movie.id } })}>

 

파람스를 프롭스할때에는

 route: {

    params: { WeatherId },

  },

 

라우트라는걸로 감싸줘야하고 

사용할때에는 파람스안에있는 값으로만 사용을하면된다

 

useQuery 안에서 받아올경우 

api 받아오는곳 


const getNowWeather = (params) => {
  const [_, WeatherId] = params.queryKey;
  console.log(WeatherId);
  return fetch(`${BASE_URL}id=${WeatherId}&appid=${API_KEY}&units=Metric`).then(
    (res) => res.json()
  );
  
 프롭스로 params 가져오기
  const City = ({
  route: {
    params: { WeatherId },
  },
})


유즈쿼리에 박아주기
const { data: getWeatherData, isLoading: isLoadingWD } = useQuery(
    ["getWeather", WeatherId],
    getNowWeather
  );
728x90

+ Recent posts