Skip to content

Commit 9a7ef85

Browse files
authored
Clarify wrapComponent interface in Plugin API docs
1 parent c23b884 commit 9a7ef85

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

docs/customization/plugin-api.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const MyWrapSelectorsPlugin = function(system) {
293293

294294
Wrap Components allow you to override a component registered within the system.
295295

296-
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`.
296+
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`. If you'd prefer to provide a React component class, `(OriginalComponent, system) => ReactClass` works as well.
297297

298298
```javascript
299299
const MyWrapBuiltinComponentPlugin = function(system) {
@@ -310,9 +310,12 @@ const MyWrapBuiltinComponentPlugin = function(system) {
310310
}
311311
```
312312

313+
Here's another example that includes a code sample of a component that will be wrapped:
314+
313315
```javascript
314-
// Overriding a component from a plugin
316+
///// Overriding a component from a plugin
315317

318+
// Here's our normal, unmodified component.
316319
const MyNumberDisplayPlugin = function(system) {
317320
return {
318321
components: {
@@ -321,13 +324,15 @@ const MyNumberDisplayPlugin = function(system) {
321324
}
322325
}
323326

327+
// Here's a component wrapper defined as a function.
324328
const MyWrapComponentPlugin = function(system) {
325329
return {
326330
wrapComponents: {
327331
NumberDisplay: (Original, system) => (props) => {
328332
if(props.number > 10) {
329333
return <div>
330334
<h3>Warning! Big number ahead.</h3>
335+
<OriginalComponent {...props} />
331336
</div>
332337
} else {
333338
return <Original {...props} />
@@ -336,8 +341,30 @@ const MyWrapComponentPlugin = function(system) {
336341
}
337342
}
338343
}
344+
345+
// Alternatively, here's the same component wrapper defined as a class.
346+
const MyWrapComponentPlugin = function(system) {
347+
return {
348+
wrapComponents: {
349+
NumberDisplay: (Original, system) => class WrappedNumberDisplay extends React.component {
350+
render() {
351+
if(props.number > 10) {
352+
return <div>
353+
<h3>Warning! Big number ahead.</h3>
354+
<OriginalComponent {...props} />
355+
</div>
356+
} else {
357+
return <Original {...props} />
358+
}
359+
}
360+
}
361+
}
362+
}
363+
}
339364
```
340365

366+
367+
341368
##### fn
342369

343370
The fn interface allows you to add helper functions to the system for use elsewhere.

0 commit comments

Comments
 (0)