Re:Show HN: The simplest React state manager now at stable r...
by vaughan on Tuesday April 20, 2021 @05:04PM
(#26881649)
I think SQL on the frontend is a big opportunity. It’s a powerful declarative language that matches nicely to React.
Every component’s data requirements are essentially an SQL query, and a lot of client-state could probably be represented in further SQL queries (filtering, aggregation).
Doing joins makes things much more consistent too when the same entities are referenced in multiple places in the UI.
Just like React works declaratively by re-rendering the virtual dom, wouldn’t it be great if we just re-ran a declarative query for the data too?
Kind of like Redux (global state) I guess but a relational model version.
Re:Show HN: The simplest React state manager now at stable r...
by aenero on Tuesday April 20, 2021 @10:18AM
(#26875010)
Although this is not provided by SimpleR State out of the box, the library makes it easy to implement a "selector" function that accepts an SQL query, and pass this selector to the entity hook. This SQL query syntax in React can well be a library on its own, I suppose.
Re:Show HN: The simplest React state manager now at stable r...
by BenoitP on Tuesday April 20, 2021 @10:28AM
(#26875135)
Would that be the transform function from here [1]?
I do agree too that this definitely should be a library on its own.
Anyway thanks for your work; I'll definitely check SimpleR in my project.
[1] https://github.com/arnelenero/simpler-state/blob/f6336817c9e...
Re:Show HN: The simplest React state manager now at stable r...
by aenero on Tuesday April 20, 2021 @10:33AM
(#26875197)
Yes, I called it "transform function" in the documentation to reflect the more general functionality that also includes computed values, apart from selection ("picking" properties).
Thanks for your encouraging feedback.
I've been prototyping something server-side in the style of the SQL Kappa architecture: facts on immutable logs, possibly keyed (and compactable by key), and SQL materialized views streaming the updates with Flink. And I'm in search of a React state manager in that philosophy.
Rows are sent to each client requesting a feed of them:
But: maybe you want all the orders in the UI and do the aggregation client-side, to have all orders alongside the total. You could move the aggregation to the client side. And it would be great to have the same data language than on the server (so that business rule expression is the same).In that case, a React Hook library like SimpleR State could aggregate in SQL the sum and update the view reactively. It would look like:
I don't think that would be easy to do; but I think there is a market for it: The business folks doing no-code+SQL client-side, and they would sometimes ask through proper channels for a query to be computed globally server-side or be brought client-side.