hilla
hilla copied to clipboard
Consider creating hooks for browsercallable services
trafficstars
Describe your motivation
Using browser-callable services is not as smooth as it could be in many cases. Consider the following code for getting a list of todos from the server
const [todos, setTodos] = useState<Todo[]>([]);
useEffect(() => {
TodoService.findAll().then(setTodos);
}, []);
Describe the solution you'd like
Consider generating a hook for accessing services along the lines of:
const {data: todos, loading, error} = useTodoService();
The API would need some more consideration to handle multiple methods, etc.
Describe alternatives you've considered
Not doing it.
My ideas on "full stack state" might also fit into this problem somehow. I imagine it being something like this:
const todos = useSharedList(TodoService.findAll);
where todos has the properties value, loading, and error.