Vue.js
Guide
Setup
Add the client to your dependencies:
Add the provider to your app:
For server-side-rendering you can pass the list of active flags directly to the client so the user does not have to re-fetch this list via the API.
Read the Node.js client documentation more client specific information.
Updating the context
You can now change the context anywhere in the app using the useTggl
function:
updateContext
only updates the keys you specify, it merges the context you pass as argument into the existing context. Alternatively you can use setContext
to override the context completely.
Checking flag results
Use the useFlag
function to get the state of a flag:
You may also get the value of a flag:
Typing
Using the Tggl CLI you can run an introspection query to generate the TypeScript types for your flags and context.
Replace <SERVER_API_KEY>
with your server API key or use the TGGL_API_KEY
environment variable and omit the -k
option. You should run this command everytime you need to update the typing. Your IDE will now autocomplete and type-check the context properties and all flag names and values.
active
vs value
By design, you have no way of telling apart an inactive flag, a non-existing flag, a deleted flag, or a network error. This design choice prevents anything from breaking your app by just deleting a flag, messing up the API key rotation, or any other unforeseen event, it will simply consider any flag to be inactive.
Do not use value
if you simply want to know if a flag is active or not, use active
instead.
value
gives you the value of an active flag, and this value may be "falsy" (null, false, 0, or empty string), leading to unexpected behaviors: