Skip to content

Using twind standalone #65

Answered by sastan
mateomorris asked this question in Q&A
Discussion options

You must be logged in to vote

To expand on what Luke wrote...

Sync with default tw

import { setup } from 'twind'
import { virtualSheet, shim, getStyleTag, getStyleTagProperties } from 'twind/server'

const sheet = virtualSheet()

setup({ sheet })

function render() {
  // Start with a fresh sheet every render
  sheet.reset()

  // Replace class attributes and create styles
  const body = shim('<div class="text(2xl black)"></div>')
  // => <div class="text-2xl text-black"></div>

  console.log(sheet.target)
  // => [".text-2xl{font-size:2rem}", "text-black{color:black}"]

  console.log(getStyleTagProperties(sheet))
  // => {id: "__twind",  textContent: ".text-2xl{font-size:2rem}text-black{color:black}"}
 
  // Create a…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mateomorris
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
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
Category
Q&A
Labels
None yet
4 participants