Skip to content

Commit 25d5f80

Browse files
committed
docs: update changelog
1 parent a81bcb1 commit 25d5f80

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

.changeset/tools-react-wrappers.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,51 @@
22
"@patternfly/pfe-tools": minor
33
"@patternfly/elements": minor
44
---
5-
**React**: automatically generate react wrapper components
5+
PatternFly elements are now available wrapped in React components. While it was
6+
always possible to use PatternFly elements (or any other custom elements) in
7+
React apps, this release makes it easier to integrate them into React without
8+
the need for cumbersome workarounds to React's [poor HTML and DOM support][cee].
9+
10+
Before:
11+
12+
```jsx
13+
import { useEffect, useState, useRef } from 'react';
14+
import '@patternfly/elements/pf-switch/pf-switch.js'
15+
16+
function App () {
17+
const [checked, setChecked] = useState(false);
18+
const switchRef = useRef(null);
19+
useEffect(() => {
20+
switchRef.current.checked = checked;
21+
}, [switchRef.current, checked]);
22+
useEffect(() => {
23+
switchRef.current.addEventListener('change', () =>
24+
setChecked(switchRef.current.checked));
25+
}, [switchRef.current]);
26+
return (
27+
<>
28+
<pf-switch ref={switchRef}></pf-switch>
29+
</>
30+
);
31+
}
32+
```
33+
34+
After:
35+
36+
```jsx
37+
import { useState } from 'react';
38+
import { Switch } from '@patternfly/elements/react/pf-switch/pf-switch.js';
39+
40+
function App () {
41+
const [checked, setChecked] = useState(false);
42+
return (
43+
<>
44+
<Switch checked={checked}
45+
onChange={({ target }) =>
46+
setChecked(target.checked)}/>
47+
</>
48+
);
49+
}
50+
```
51+
52+
[cee]: https://custom-elements-everywhere.com/#react

0 commit comments

Comments
 (0)