@@ -187,11 +187,11 @@ function useLatestRef(val) {
187187 * Also calls the onChange handlers for state values that have changed.
188188 *
189189 * @param {Function } reducer Reducer function from downshift.
190- * @param {Object } initialState Initial state of the hook .
191- * @param {Object } props The hook props .
190+ * @param {Object } props The hook props, also passed to createInitialState .
191+ * @param {Function } createInitialState Function that returns the initial state .
192192 * @returns {Array } An array with the state and an action dispatcher.
193193 */
194- function useEnhancedReducer ( reducer , initialState , props ) {
194+ function useEnhancedReducer ( reducer , props , createInitialState ) {
195195 const prevStateRef = useRef ( )
196196 const actionRef = useRef ( )
197197 const enhancedReducer = useCallback (
@@ -206,7 +206,11 @@ function useEnhancedReducer(reducer, initialState, props) {
206206 } ,
207207 [ reducer ] ,
208208 )
209- const [ state , dispatch ] = useReducer ( enhancedReducer , initialState )
209+ const [ state , dispatch ] = useReducer (
210+ enhancedReducer ,
211+ props ,
212+ createInitialState ,
213+ )
210214 const propsRef = useLatestRef ( props )
211215 const dispatchWithProps = useCallback (
212216 action => dispatch ( { props : propsRef . current , ...action } ) ,
@@ -234,12 +238,16 @@ function useEnhancedReducer(reducer, initialState, props) {
234238 * returning the new state.
235239 *
236240 * @param {Function } reducer Reducer function from downshift.
237- * @param {Object } initialState Initial state of the hook .
238- * @param {Object } props The hook props .
241+ * @param {Object } props The hook props, also passed to createInitialState .
242+ * @param {Function } createInitialState Function that returns the initial state .
239243 * @returns {Array } An array with the state and an action dispatcher.
240244 */
241- function useControlledReducer ( reducer , initialState , props ) {
242- const [ state , dispatch ] = useEnhancedReducer ( reducer , initialState , props )
245+ function useControlledReducer ( reducer , props , createInitialState ) {
246+ const [ state , dispatch ] = useEnhancedReducer (
247+ reducer ,
248+ props ,
249+ createInitialState ,
250+ )
243251
244252 return [ getState ( state , props ) , dispatch ]
245253}
0 commit comments