File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
packages/react-reconciler/src/__tests__ Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1212
1313'use strict' ;
1414
15+ import { useInsertionEffect } from 'react' ;
16+
1517describe ( 'useRef' , ( ) => {
1618 let React ;
1719 let ReactNoop ;
@@ -403,4 +405,37 @@ describe('useRef', () => {
403405 span ( 'Count: 34' ) ,
404406 ] ) ;
405407 } ) ;
408+
409+ it ( 'is mutated before all other effects' , ( ) => {
410+ function Counter ( { value} ) {
411+ useInsertionEffect ( ( ) => {
412+ Scheduler . unstable_yieldValue ( 'Effect value: ' + value ) ;
413+ increment ( ) ;
414+ } , [ value ] ) ;
415+
416+ // This is defined after the insertion effect, but it should
417+ // update the event fn _before_ the insertion effect fires.
418+ const increment = useEvent ( ( ) => {
419+ Scheduler . unstable_yieldValue ( 'Event value: ' + value ) ;
420+ } ) ;
421+
422+ return (
423+ < >
424+ </ >
425+ ) ;
426+ }
427+
428+ ReactNoop . render ( < Counter value = { 1 } /> ) ;
429+ expect ( Scheduler ) . toFlushAndYield ( [
430+ 'Effect value: 1' ,
431+ 'Event value: 1' ,
432+ ] ) ;
433+
434+
435+ act ( ( ) => ReactNoop . render ( < Counter value = { 2 } /> ) ) ;
436+ expect ( Scheduler ) . toHaveYielded ( [
437+ 'Effect value: 2' ,
438+ 'Event value: 2' ,
439+ ] ) ;
440+ } ) ;
406441} ) ;
You can’t perform that action at this time.
0 commit comments