File tree Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Original file line number Diff line number Diff line change
1
+ import { Component , createElement as h } from 'react' ;
2
+ import { storiesOf } from '@storybook/react' ;
3
+ import { action } from '@storybook/addon-actions' ;
4
+ import { linkTo } from '@storybook/addon-links' ;
5
+ import { createRef } from '../createRef' ;
6
+ import ShowDocs from '../../../.storybook/ShowDocs'
7
+
8
+ class Example extends Component < any , any > {
9
+ divRef = createRef ( ) ;
10
+
11
+ onClick = ( ) => {
12
+ console . log ( 'ref' , this . divRef . value ) ;
13
+ } ;
14
+
15
+ render ( ) {
16
+ return < div ref = { this . divRef } onClick = { this . onClick } > foobar</ div > ;
17
+ }
18
+ }
19
+
20
+ storiesOf ( 'Shims/createRef()' , module )
21
+ . add ( 'Basic example' , ( ) => < Example /> ) ;
Original file line number Diff line number Diff line change 1
- const shimCreateRef = ( React ) => {
2
- if ( typeof React . createRef !== 'function' ) {
3
- React . createRef = ( ) => {
4
- const ref : any = ( el ) => {
5
- ref . value = el ;
6
- } ;
1
+ export const createRef = ( ) => {
2
+ const ref : any = ( el ) => {
3
+ ref . value = el ;
4
+ } ;
7
5
8
- return ref ;
9
- } ;
10
- }
6
+ return ref ;
11
7
} ;
12
-
13
- export default shimCreateRef ;
You can’t perform that action at this time.
0 commit comments