question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API consideration: return `tw` from `setup` function

See original GitHub issue

So one issue I notice with the way the API works, is that you have to manually ensure tw is only called after setup. Integrating twind in my Next.js project and having followed the examples, even then, I’m still getting some “late setup call” errors, which I think is a sign that this constraint can’t be reliably followed

Suggestion: when needing a config override, the user should create their own tw file which includes the setup call. Setup returns the tw function, which is then imported throughout the app for styling. Logically, this ensures that setup can’t be called after tw. To clarify:

// tw.ts
import { setup } from "twind"

export const tw = setup({
	theme: { colors: { palevioletred: "palevioletred" } },
})

// Button.tsx
import { tw } from "./tw"

export const Button = () => (
	<button type="button" className={tw`p-3 rounded bg-blue-500 text-white`}>
		hi
	</button>
)

With the current API, it’s true that one could also reexport tw from the tw.ts file. My suggestion is to make this API change to possibly enforce using the returned tw function, and/or document that usage

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
itsMapleLeafcommented, Jan 1, 2021

Yeah, that’s fine. I can post my repo over there

1reaction
sastancommented, Jan 1, 2021

Thanks for the report. Could you share a repo where this happens?

We should make it more clear that setup should be called in the main entry file. The idea is that the setup export modifies the tw export to allow libraries to use import { tw } from 'twind' while the application is may configure tw using setup.

What you are trying is already possible using the yet undocumented create export (see Web Components example):

// tw.ts
import { create } from "twind"

export const { tw } = create({
	theme: { colors: { palevioletred: "palevioletred" } },
})

I hope that helps…

PS: Sorry for the inconvenience we are still working on the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

composition api computed return value in setup function ...
Since you're using async calls in your setup, you can change the setup to an async setup and then await those inner async...
Read more >
Composition API: setup() - Vue.js
setup () should return an object synchronously. The only case when async setup() can be used is when the component is a descendant...
Read more >
Best practices for REST API design - Stack Overflow Blog
Best practices for REST API design · Accept and respond with JSON · Use nouns instead of verbs in endpoint paths · Name...
Read more >
An ultimate guide to the Vue 3 Composition API
The setup() function returns state and other defined variables so that the component's template can access them.
Read more >
5 Golden Rules for Great Web API Design - Toptal
Front-loading the API version before all the resources means you are migrating the entire API at once. Putting it after the resource means...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found