3 ms·
The thing I like about hooks is that components can be truly modular in terms of both behaviour and state. They can so be relatively easy to reason about in iso
by rebotfc 7y ago
The thing I like about hooks is that components can be truly modular in terms of both behaviour and state. They can so be relatively easy to reason about in isolation and therefore it's easier to reuse them with less plumbing needed.
For instance a simple custom hook use_graphql_list(url,query) can encapsulate the entirety of fetching json via a graphql query keeping an array up to date and in sync and present data in a format that is easy to use in a list component.
For instance in rust:
let graphql_query = "{countries {name currency emoji}}";
let graphql_url = "https://countries.trevorblades.com/";
let container_name = "countries";
let (list, graphql_control) =
use_graphql_list::<Country>(
graphql_query,
graphql_url,
container_name);