Skip to content

Conversation

@JulianCataldo
Copy link

Hi :) Thanks for chiming in making Lit compatible with React Query!

This fixes build, so the root nx command, build:all, can succeed.

See
```ts
if (error) return 'An error has occurred: ' + error.message
```

in react/simple example
@JulianCataldo
Copy link
Author

JulianCataldo commented Sep 14, 2024

Added a working "lit simple" example + fixed a typing mismatch. It looks like react-query is using Error | null instead of unknown.

Was using `unknown` at the beginning.
It's now aligned with others implementations.
@JulianCataldo JulianCataldo changed the title build: align with react/solid… instead of svelte-package Align build with react/solid/… instead of svelte-package | fix default error typing | add simple example Sep 14, 2024
@JulianCataldo JulianCataldo changed the title Align build with react/solid/… instead of svelte-package | fix default error typing | add simple example Align build with react/solid/… instead of svelte | fix default error typing | add simple example Sep 14, 2024
@JulianCataldo
Copy link
Author

JulianCataldo commented Sep 14, 2024

Added a mutation observer controller, with correct typings (from react-query etc.)
Build is OK.
A very quick runtime test was done, at least onSuccess seems to work.

@customElement('child-element')
export class ChildElement extends LitElement {
  @state() todoId = 1

  private todoQuery = todoQueryController(this)

  private todoMutation = new MutationController(this, () => ({
    mutationFn: (newTodo: { id: string }) => {
      console.log('OK')

      return new Promise((r) => r({}))
    },
  }))

 render() {
    const { isPending, error, data, isFetching } = this.todoQuery.result

    if (error) return 'An error has occurred: ' + error.message

    return html`

        <button
          @click=${() => {
            this.todoMutation.result.mutate(
              { id: 'string' },
              {
                onSuccess: () => {
                  console.log('OK')
                  queryClient.invalidateQueries({ queryKey: ['todo'] })
                },
              },
            )
          }}
        >
          MUTATE
        </button>
`
//...

}

@JulianCataldo JulianCataldo changed the title Align build with react/solid/… instead of svelte | fix default error typing | add simple example Align build with react/solid/… instead of svelte | fix default error typing | add simple example | add mutation controller Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant