Skip to content

import zustand in HTML file #1952

Closed Answered by thipages
thipages asked this question in General
Jul 23, 2023 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

Thank you, this is working fine now. Code example:

import { createStore } from 'https://esm.sh/zustand/vanilla'

const store = createStore((set) => ({
    bears: 0
}))
const { getState, setState, subscribe, destroy } = store
setState((state) => ( {bears : state.bears +1} ) )
console.log(getState((state) => state.bears)) // prints {bears: 1}

from my original question :

  • 🙅 adding a reference in an html file (in a script tag either via module or importmap type) is not relevant cause of the dynamic build /external reference of esm.sh.
  • 🆗 import can be done directly in an esm module through import { createStore } from 'https://esm.sh/zustand/vanilla'

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@dbritto-dev
Comment options

@thipages
Comment options

@dbritto-dev
Comment options

@thipages
Comment options

Answer selected by thipages
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants