Skip to content

Commit 3c06b3e

Browse files
committed
1 parent 0eab439 commit 3c06b3e

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

.size-snapshot.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"dist/react-render-callback.umd.js": {
3-
"bundled": 4399,
4-
"minified": 1771,
5-
"gzipped": 759
3+
"bundled": 4334,
4+
"minified": 1702,
5+
"gzipped": 746
66
},
77
"dist/react-render-callback.esm.js": {
8-
"bundled": 2730,
9-
"minified": 1567,
10-
"gzipped": 649,
8+
"bundled": 2665,
9+
"minified": 1526,
10+
"gzipped": 638,
1111
"treeshaked": {
1212
"rollup": {
1313
"code": 289,
@@ -19,13 +19,13 @@
1919
}
2020
},
2121
"dist/react-render-callback.cjs.js": {
22-
"bundled": 2903,
23-
"minified": 1695,
24-
"gzipped": 686
22+
"bundled": 2838,
23+
"minified": 1654,
24+
"gzipped": 677
2525
},
2626
"dist/react-render-callback.umd.min.js": {
27-
"bundled": 4432,
28-
"minified": 1757,
29-
"gzipped": 749
27+
"bundled": 4367,
28+
"minified": 1688,
29+
"gzipped": 737
3030
}
3131
}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ It can render the following types:
6060
- [Elements](https://reactjs.org/docs/glossary.html#elements)
6161
with [optional support](#use-optionscloneelement) for [cloning][clone-element] to merge props
6262
- primitives like strings, numbers, arrays, ...
63-
- `false`, `null`, `undefined`, `NaN` and an empty string are coerced to `null`
63+
- `false`, `null`, `undefined` and `true` are returned as `null`
64+
just like in [JSX](https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored)
6465

6566
View an example in [codesandbox.io](https://codesandbox.io/s/48k5p1r764?module=%2FApp.js).
6667

@@ -146,7 +147,8 @@ const render = require('react-render-callback')
146147

147148
**returns**
148149

149-
- `null` for `false`, `null`, `undefined`, `NaN` and an empty string
150+
- `false`, `null`, `undefined` and `true` are returned as `null`
151+
just like in [JSX](https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored)
150152
- the value as is for all other values
151153

152154
#### `createRender([ renderable [, options ] ])`

src/createRender.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {isValidElement, createElement, cloneElement} from 'react'
33
import isPlainObject from 'is-plain-object'
44

55
import constant from './internal/constant'
6-
import falsyToNull from './internal/falsyToNull'
6+
import ignoredValuesToNull from './internal/ignoredValuesToNull'
77
import isReactComponent from './internal/isReactComponent'
88

99
export default (renderable, options) => {
@@ -14,15 +14,11 @@ export default (renderable, options) => {
1414
if (typeof renderable === 'function') {
1515
return (...args) => {
1616
const element =
17-
args.length === 1 && isPlainObject(args[0])
18-
? renderable(
19-
renderable.defaultProps
20-
? {...renderable.defaultProps, ...args[0]}
21-
: args[0],
22-
)
17+
renderable.defaultProps && args.length === 1 && isPlainObject(args[0])
18+
? renderable({...renderable.defaultProps, ...args[0]})
2319
: renderable(...args)
2420

25-
return falsyToNull(element)
21+
return ignoredValuesToNull(element)
2622
}
2723
}
2824

@@ -31,5 +27,5 @@ export default (renderable, options) => {
3127
}
3228

3329
// must be something else
34-
return constant(falsyToNull(renderable))
30+
return constant(ignoredValuesToNull(renderable))
3531
}

src/internal/falsyToNull.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import isIgnored from './isIgnored'
2+
3+
export default value => (isIgnored(value) ? null : value)

src/internal/isFalsy.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/internal/isIgnored.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value == null || value === false || value === true

src/render.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ describe('render([renderable[, props]])', () => {
5555
})
5656

5757
describe('should return null for', () => {
58-
;[false, null, undefined, NaN, ''].forEach(value => {
58+
;[false, null, undefined, true].forEach(value => {
5959
it(`${value}`, () => {
6060
expect(render(value)).toBeNull()
6161
})
6262
})
6363
})
6464

6565
describe('should return value', () => {
66-
;[true, 0].forEach(value => {
66+
;['', 0, NaN].forEach(value => {
6767
it(`${value}`, () => {
6868
expect(render(value)).toBe(value)
6969
})
@@ -208,15 +208,15 @@ Object {
208208
const SFC = ({value}) => value
209209

210210
describe('return null for', () => {
211-
;[false, null, undefined, NaN, ''].forEach(value => {
211+
;[false, null, undefined, true].forEach(value => {
212212
it(`${value}`, () => {
213213
expect(render(SFC, {value})).toBeNull()
214214
})
215215
})
216216
})
217217

218218
describe('return value', () => {
219-
;[true, 0].forEach(value => {
219+
;['', 0, NaN].forEach(value => {
220220
it(`${value}`, () => {
221221
expect(render(SFC, {value})).toBe(value)
222222
})

0 commit comments

Comments
 (0)