Comments (3)
Hi, the first argument of onChange is the previous flags, as can be seen here / in TypeScript, this allows you to compare changes, the previous flags would be null unless you provided flag defaults. To get the current flags you would use the flagsmith SDK e.g. flagsmith.hasFeature('test')
.
As for useFlags not having any value, I'll try and replicate this and get back to you however I'd expect it to contain the flags from cache. e.g.
const {test} = useFlags(['test'])
from flagsmith-js-client.
Given the following on flagsmith: "^3.23.2" I can see useFlags being populated with cache, so I may need more information.
//App
ReactDOM.render(
<FlagsmithProvider options={{
environmentID: "QjgYur4LQTwe5HpvbvhpzK",
cacheFlags: true,
cacheOptions: {
ttl: 10000000,
skipAPI: true,
},
onChange(a, b, c) {
console.log('onchange', a, b, c); // a is null
}
}} flagsmith={flagsmith}>
<App />
</FlagsmithProvider>,
document.getElementById('root')
);
// HomePage
function App() {
const flags = useFlags(['font_size']); // only causes re-render if specified flag values / traits change
return (
<div className='App'>
font_size: {flags.font_size?.value}
</div>
);
}
Output:
![image](https://private-user-images.githubusercontent.com/8608314/312399135-64c3cdb2-45bc-4394-9859-624db5aba494.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTYzMDIyOTQsIm5iZiI6MTcxNjMwMTk5NCwicGF0aCI6Ii84NjA4MzE0LzMxMjM5OTEzNS02NGMzY2RiMi00NWJjLTQzOTQtOTg1OS02MjRkYjVhYmE0OTQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MjFUMTQzMzE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmQxNjIxMTk5MGQyZTAxZGQzOTlkYTg2ODNlYzU4N2Y2OTQxYzJlYjBjZjNkYmY2MjJmN2EwMGI2ODc0NmM5OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.gzCXF6M1-rbRl9nrQTMqqbGb9GCuuNE3ERk2hLnS3MI)
from flagsmith-js-client.
Hey @dawiidio , hopefully the above clarifies things. If there's still an issue please re-open this and I'll take a look.
from flagsmith-js-client.
Related Issues (20)
- Flagsmith's `loadingState.error` is not respect actual error state HOT 11
- [Bug] - NextJS >= 13.0.0 SSR `useFlagsmith` state not matching the state that is passed to the provider. HOT 16
- flagsmith/react only works in React 18 HOT 3
- [Bug] - TypeError: Cannot read properties of null (reading 'getValue') HOT 5
- Flagsmith's 'useFlags' doesn't return actual cached flags when request failed HOT 2
- Rollup Name for react HOT 5
- Inconsistent license information HOT 2
- Caching with multiple instance doesn't work HOT 6
- Typing issue in react.tsx: 'flagsmith' is possibly 'null' HOT 3
- useFlags() race condition HOT 8
- Different environments not working HOT 5
- Localstorage cache is not being wiped out in some edge cases HOT 3
- Support `getValue` fallback without `json` flag HOT 2
- useFlags not updating values in react18/Nextjs App Router HOT 1
- 3.23.0 seems to have broken something HOT 4
- Intermittent Flakiness in Feature Flags on Safari/MacOS HOT 2
- Typescript compiler errror `Cannot find name 'F'.` when compiling flagsmith in Angular project HOT 3
- Bundle ES(flagsmith-es) and combine with standard CJS module (flagsmith)
- Identifier/trait confusion when using `cacheOptions: { skipAPI: true } ` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flagsmith-js-client.