File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,19 @@ describe('Hook', () => {
210210 expect ( children ) . toHaveBeenCalledTimes ( 1 ) ;
211211 expect ( children ) . toHaveBeenCalledWith ( undefined , actions ) ;
212212 } ) ;
213+
214+ it ( 'should support selectors returning a function on init and update' , ( ) => {
215+ const selector = state => ( { id } ) => state [ id ] ;
216+ const { getMount, children } = setup ( { } , selector ) ;
217+ getMount ( ) ;
218+
219+ const newState = { count : 1 } ;
220+ storeStateMock . getState . mockReturnValue ( newState ) ;
221+ const update = storeStateMock . subscribe . mock . calls [ 0 ] [ 0 ] ;
222+ act ( ( ) => update ( storeStateMock . getState ( ) , storeStateMock ) ) ;
223+
224+ expect ( children ) . toHaveBeenCalledWith ( expect . any ( Function ) , actions ) ;
225+ } ) ;
213226} ) ;
214227
215228describe ( 'createMemoizedSelector' , ( ) => {
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ export function createHook(Store, { selector } = {}) {
5353 const currentState = stateSelector ( storeState . getState ( ) , propsArg ) ;
5454 useDebugValue ( currentState ) ;
5555
56- const triggerUpdate = useState ( currentState ) [ 1 ] ;
56+ const triggerUpdate = useState ( ( ) => currentState ) [ 1 ] ;
5757 const propsRef = useRef ( propsArg ) ;
5858 propsRef . current = propsArg ;
5959
@@ -70,7 +70,7 @@ export function createHook(Store, { selector } = {}) {
7070 const nextState = stateSelector ( updatedState , propsRef . current ) ;
7171
7272 if ( nextState !== prevState ) {
73- triggerUpdate ( nextState ) ;
73+ triggerUpdate ( ( ) => nextState ) ;
7474 prevState = nextState ;
7575 }
7676 } ;
You can’t perform that action at this time.
0 commit comments