Skip to content

Commit

Permalink
docs(react): update ref documentation
Browse files Browse the repository at this point in the history
the previous API no longer worked after the switch to lib-labs/react

switch to hooks

Signed-off-by: Ashley Ryan <asryan@vmware.com>
  • Loading branch information
Ashley Ryan authored and ashleyryan committed Dec 15, 2021
1 parent c77f0a8 commit 5acebdc
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions packages/core/docs/react.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,21 @@ React elements created in the render method. Because web components' lifecycle l
lifecycle our components provide a way to use refs when the underlying web component has finished rendering:

```typescript
import React from 'react';
import React, { useEffect, useRef } from 'react';
import { CdsButton } from '@cds/react/button';

export default class App extends React.Component<{}, {}> {
buttonRef: React.RefObject<CdsButton>;

constructor(props: any) {
super(props);
this.buttonRef = React.createRef<CdsButton>();
}

componentDidMount() {
this.buttonRef.current.nativeElement.then(element => {
element.focus();
});
}

render() {
return (
<div>
<CdsButton ref={this.buttonRef}>My button</CdsButton>
</div>
);
}
export function App() {
const buttonRef = useRef<typeof CdsButton & HTMLElement>();

useEffect(() => {
buttonRef.current?.focus();
}, []);

return (
<div>
<CdsButton ref={buttonRef}>My button</CdsButton>
</div>
);
}
```

Expand Down

0 comments on commit 5acebdc

Please sign in to comment.