hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Consider creating hooks for browsercallable services

Open marcushellberg opened this issue 2 years ago • 1 comments
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.

marcushellberg avatar Nov 07 '23 21:11 marcushellberg

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.

Legioth avatar Nov 08 '23 08:11 Legioth