Skip to content

Commit d06e3fa

Browse files
author
Sven Tschui
committed
Support falsy context value
1 parent a93830c commit d06e3fa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function renderToString(vnode, context, opts, inner, isSvgMode, selectValue) {
8383
let cctx = cxType != null ? (provider ? provider.props.value : cxType._defaultValue) : context;
8484

8585
// stateless functional components
86-
rendered = nodeName.call(vnode.__c, props, cctx || context);
86+
rendered = nodeName.call(vnode.__c, props, cctx);
8787
}
8888
else {
8989
// class-based components

test/context.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@ describe('context', () => {
3030
<section>value is: correct</section>
3131
`);
3232
});
33+
34+
it('should support falsy context value', () => {
35+
const { Provider, Consumer } = createContext();
36+
let rendered = renderJsx(
37+
<Provider value={null}>
38+
<Consumer>
39+
{(value) => (
40+
<section>
41+
value is: {value}
42+
</section>
43+
)}
44+
</Consumer>
45+
</Provider>
46+
);
47+
48+
expect(rendered).to.equal(dedent`
49+
<section>value is: </section>
50+
`);
51+
});
3352
});

0 commit comments

Comments
 (0)