cli: add presets option and react preset for typescript #2780
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
Implements
--preset
option inspacetime generate
cli to provide a way to generatereact
code undertypescript
module binding.Exemple:
For the moment it's a draft because I'd like to get your feedback first:
This is my very first Rust code, so I look forward to your feedback 😇
Implementation Details
Preset
enum in the CLI to support React preset generationReact
struct inpresets/react/mod.rs
that implements theLangPreset
traituseSyncExternalStore
Exenple of generated code:
You can find more detailed exemple here:
crates/codegen/src/presets/react/doc.md
.For now, there aren't many hooks available, but I'm planning to add some to handle the calls from the reducers in the next few days.
Design issue
Actually,
REACT_SPACETIME_CONTEXT_PROVIDER
doesn't need to be generated and could be a part of with areact-sdk
inspacetimedb-typescript-sdk
.The hooks need to be wrap in a React Context (
SpacetimeProvider
) to be able to use theuseSpacetimeContext
hooks and use the connected client (to avoid passing Spacetime client each time in props). I don't know if this is a good thing or a bad thing.Testing
Todo list
REACT_SPACETIME_CONTEXT_PROVIDER
to a separatereact-sdk
package inside spacetimedb-typescript-sdkFuture Improvements