Skip to content

Commit 75fbc77

Browse files
committed
pass though sizeMe config prop 'noPlaceholder'
1 parent f36630f commit 75fbc77

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ componentQueries({
193193
- `[monitorWidth]` (_Boolean_): If `true` then the width of your component will be tracked and provided within the `size` argument to your query functions. Defaults to `true`.
194194
- `[monitorHeight]` (_Boolean_): If `true` then the height of your component will be tracked and provided within the `size` argument to your query functions. Defaults to `false`.
195195
- `[refreshRate]` (_Number_): The maximum frequency, in milliseconds, at which size changes should be recalculated when changes in your Component's rendered size are being detected. This must not be set to lower than 16. Defaults to `16`.
196+
- `[noPlaceholder]` (_Boolean_): By default we render a "placeholder" component initially so we can try and "prefetch" the expected size for your component. This is to avoid any unnecessary deep tree renders. If you feel this is not an issue for your component case and you would like to get an eager render of your component then disable the placeholder using this config option. Defaults to `false`.
196197
- `[pure]` (_Boolean_): Indicates if your component should be considered "pure", i.e. it should only be rerendered if the result of your query functions change, or if new props are provided to the wrapped component. If you set it to false then the wrapped component will render _every_ time the size changes, even if it doesn't result in new query provided props. Defaults to `true`.
197198
- [`conflictResolver(prev, current, key) : Any`] \(_Function_): A custom function to use in order to resolve prop conflicts when two or more query functions return a prop with the same key. This gives you an opportunity to do custom resolution for special prop types, e.g. `className` where you could instead concat the conflicted values. The default implementation will return the value from the _last_ query function provided in the query array. Please read the respective section further down in the readme for more info and examples of this.
198199
- `prev` (_Any_): The value of the conflicted prop provided by the previously executed query function.

src/__tests__/componentQueries.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ describe('Given the ComponentQueries library', () => {
9292
sizeMeConfig: {
9393
monitorHeight: true,
9494
monitorWidth: false,
95+
noPlaceholder: true,
9596
refreshRate: 200,
9697
},
9798
})(() => <div />)
@@ -100,6 +101,7 @@ describe('Given the ComponentQueries library', () => {
100101
monitorHeight: true,
101102
monitorWidth: false,
102103
refreshRate: 200,
104+
noPlaceholder: true,
103105
})
104106
})
105107
})
@@ -115,6 +117,7 @@ describe('Given the ComponentQueries library', () => {
115117
monitorWidth: false,
116118
refreshRate: 200,
117119
refreshMode: 'debounce',
120+
noPlaceholder: true,
118121
conflictResolver,
119122
},
120123
})(() => <div />)
@@ -124,6 +127,7 @@ describe('Given the ComponentQueries library', () => {
124127
monitorWidth: false,
125128
refreshRate: 200,
126129
refreshMode: 'debounce',
130+
noPlaceholder: true,
127131
})
128132
})
129133
})

src/componentQueries.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const defaultConfig = {
1111
monitorWidth: true,
1212
refreshRate: 16,
1313
pure: true,
14+
noPlaceholder: false,
1415
}
1516

1617
const defaultConflictResolver = (x, y) => y
@@ -49,20 +50,19 @@ function componentQueries(...params) {
4950
monitorWidth,
5051
refreshRate,
5152
refreshMode,
53+
noPlaceholder,
5254
} = params[0].config
5355
sizeMeConfig = {
54-
monitorHeight: monitorHeight != null
55-
? monitorHeight
56-
: defaultConfig.monitorHeight,
57-
monitorWidth: monitorWidth != null
58-
? monitorWidth
59-
: defaultConfig.monitorWidth,
60-
refreshRate: refreshRate != null
61-
? refreshRate
62-
: defaultConfig.refreshRate,
63-
refreshMode: refreshMode != null
64-
? refreshMode
65-
: defaultConfig.refreshMode,
56+
monitorHeight:
57+
monitorHeight != null ? monitorHeight : defaultConfig.monitorHeight,
58+
monitorWidth:
59+
monitorWidth != null ? monitorWidth : defaultConfig.monitorWidth,
60+
refreshRate:
61+
refreshRate != null ? refreshRate : defaultConfig.refreshRate,
62+
refreshMode:
63+
refreshMode != null ? refreshMode : defaultConfig.refreshMode,
64+
noPlaceholder:
65+
noPlaceholder != null ? noPlaceholder : defaultConfig.noPlaceholder,
6666
}
6767
}
6868
conflictResolver =

0 commit comments

Comments
 (0)