useHistory / useLotation
useHistory / useLotation 는 react에서 화면전환에 사용된다.
- useHistory hook
const history = useHistory (); //useHistory로 history얻고,
const onSearchSubmit = () => {
const { searchTerm }getValues ();
history.push({
pathname: "/search", //pathname은 이동할곳.
search: `?term=${searchTerm}`, //search는 url에서 Query를 가리킴.
state: { //state는 POST data. 데이터를 url에 보이지 않고 넘김.
searchTerm,
}
});
}
- useLotation
useHistory Hook에서 보낸것을 받는다.
const location = useLocation();
useEffect (() => {
console.log(location);
} , [location];
-> useLocation을 통해 받으면 된다.
{pathname: "/search , search: "?term=ooo, hash: "", key:"dmd10g"}
Author And Source
이 문제에 관하여(useHistory / useLotation), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@sseunn/useHistory-useLotation저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)