marp | theme | html |
---|---|---|
true |
ctheme |
true |
- URL state
- Server state
- Form state
- Local state
- App state
Tools that simplify work with URLs are often referred as "routers"
<BrowserRouter>
<Routes>
<Route path="/" element={<App />}>
<Route index element={<Home />} />
<Route path="teams" element={<Teams />}>
<Route path=":teamId" element={<Team />} />
<Route path="new" element={<NewTeamForm />} />
<Route path="users/:userID" element={<UserProfile />} />
import { useParams } from 'react-router-dom';
function ProfilePage() {
// Get the userID param from the URL.
let { userID } = useParams();
// ...
}
import { useSearchParams, useNavigate } from "react-router-dom";
function App() {
let [searchParams, setSearchParams] = useSearchParams();
let navigate = useNavigate(); // --> navigate("/posts")
...
Keeps track of useful metadata for fields and form such as
isDirty
, dirtyFields
, touchedFields
, isSubmitted
, isSubmitSuccessful
, isSubmitting
, isValid
, errors
, ...
Keeps track of useful metadata describing communication with BE resource:
isLoading
, error
, ...
Also can include caching, normalization, optimistic updates and other advanced techniques
const { status, data, error, isFetching } = usePosts();
const getPosts = async () => {
const { data } = await axios.get(
"https://jsonplaceholder.typicode.com/posts"
);
return data;
};
export default function usePosts() {
return useQuery("posts", getPosts);
}
- https://react-query.tanstack.com
- https://redux-toolkit.js.org/rtk-query/overview
- https://swr.vercel.app
Some data in time that affects the whole application
- https://reactjs.org/docs/hooks-reference.html#usecontext
- https://redux-toolkit.js.org
- https://jotai.org/
- ... dozens of ther libs
<style scoped>ul li { font-size: 0.8rem; }</style>