Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Always call initialRenderCallback, 4.0.0 (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdushane committed Apr 23, 2019
2 parents eef3b5d + 55b05b1 commit d6c5e1b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-launch-darkly",
"version": "3.1.1",
"version": "4.0.0",
"description": "",
"main": "./build/index",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/components/FeatureFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function FeatureFlag (props:FeatureFlagType) {
<LaunchDarklyConsumer>
{
(config) => {
if (config) {
return (<FeatureFlagRenderer {...config} {...props} />);
if (config || props.initialRenderCallback) {
return (<FeatureFlagRenderer {...(config || {})} {...props} />);
}

return null;
Expand Down
14 changes: 14 additions & 0 deletions test/components/FeatureFlag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,19 @@ describe("components/FeatureFlag", () => {
const renderer = subject.find(FeatureFlagRenderer);
expect(renderer).toHaveLength(0);
});
it("renders the initial render callback, even if LD config is absent", () => {
const initialRenderCallback = jest
.fn()
.mockReturnValue(<div>"initial rendered"</div>);
mount(
<LaunchDarkly>
<FeatureFlag
{...defaultProps}
initialRenderCallback={initialRenderCallback}
/>
</LaunchDarkly>
);
expect(initialRenderCallback).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit d6c5e1b

Please sign in to comment.