20
loading...
This website collects cookies to deliver better user experience
we now have to deal with a completely new concept, the Store, and care about a bunch of new things, such as designing and maintaining Store structure, appropriately updating data in the Store, data normalization, mutable vs immutable, a single store vs multiple stores, and so on.
state management libraries require us to learn a new vocabulary: Actions, Action Creators, Reducers, Middlewares, Thunks, and so on.
the introduced complexity and lack of clarity forced developers to create styleguides on how to work with the Store, what to do and what to avoid.
as a result, our applications became very tangled and coupled. Frustrated developers try to mitigate the issues by inventing new state management libraries with different syntax.
queries/
folder exposes fetch and mutation methods wrapped into React Query.import { useParams } from 'react-router-dom';
import { useBookQuery } from 'queries/useBookQuery';
import { useAuthorQuery } from 'queries/useAuthorQuery';
import Presentation from './Presentation';
import Loading from './Loading';
import Error from './Error';
export default BookDetailsContainer() {
const { bookId } = useParams();
const { data: book, isError: isBookError } = useBookQuery(bookId);
const { data: author, isError: isAuthorError } = useAuthorQuery(book?.author);
if (book && author) {
return <Presentation book={book} author={author} />
}
if (isBookError || isAuthorError) {
return <Error />
}
return <Loading />
}
bookId
in the URL./queries
folder. Again, the risk of breaking any other parts of the application is very limited.