Skip to content

firstThatWorks should not be called at runtime, but runtime is the only way to reference an image (url(${myImage.src})) #949

Answered by nmn
Dattaya asked this question in Q&A
Discussion options

You must be logged in to vote

You should only be using values passed in as arguments:

const styles = stylex.create({
  dynamic: (jpgSource, avifSource) => ({
    backgroundImage: stylex.firstThatWorks(
      `var(--paletteTitleBackground), url('${jpgSource}')`,
      `var(--paletteTitleBackground), image-set(
        url('${avifSource}') type('image/avif'),
        url('${jpgSource}') type('image/jpeg')
      )`
    ),
  }),
})

If this still doesn't work, please open an issue as it should work.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Dattaya
Comment options

Answer selected by Dattaya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants