Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useFormState's permalink option changes form target #27302

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Rename useFormState url arg to permalink
Communicates the intent a bit better
  • Loading branch information
acdlite committed Aug 28, 2023
commit 3319e8b8b2062f8fcbca33e0598f6502aa382c46
4 changes: 2 additions & 2 deletions packages/react-dom-bindings/src/shared/ReactDOMFormActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export function useFormStatus(): FormStatus {
export function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
if (!(enableFormActions && enableAsyncActions)) {
throw new Error('Not implemented.');
} else {
const dispatcher = resolveDispatcher();
// $FlowFixMe[not-a-function] This is unstable, thus optional
return dispatcher.useFormState(action, initialState, url);
return dispatcher.useFormState(action, initialState, permalink);
}
}
40 changes: 20 additions & 20 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ function formStateReducer<S>(oldState: S, newState: S): S {
function mountFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
// State hook. The state is stored in a thenable which is then unwrapped by
// the `use` algorithm during render.
Expand Down Expand Up @@ -2063,7 +2063,7 @@ function mountFormState<S, P>(
function updateFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
const stateHook = updateWorkInProgressHook();
const currentStateHook = ((currentHook: any): Hook);
Expand All @@ -2072,7 +2072,7 @@ function updateFormState<S, P>(
currentStateHook,
action,
initialState,
url,
permalink,
);
}

Expand All @@ -2081,7 +2081,7 @@ function updateFormStateImpl<S, P>(
currentStateHook: Hook,
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
const [thenable] = updateReducerImpl<Thenable<S>, Thenable<S>>(
stateHook,
Expand Down Expand Up @@ -2121,7 +2121,7 @@ function formStateActionEffect<S, P>(
function rerenderFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
// Unlike useState, useFormState doesn't support render phase updates.
// Also unlike useState, we need to replay all pending updates again in case
Expand All @@ -2140,7 +2140,7 @@ function rerenderFormState<S, P>(
currentStateHook,
action,
initialState,
url,
permalink,
);
}

Expand Down Expand Up @@ -3628,11 +3628,11 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
mountHookTypesDev();
return mountFormState(action, initialState, url);
return mountFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -3798,11 +3798,11 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
updateHookTypesDev();
return mountFormState(action, initialState, url);
return mountFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -3970,11 +3970,11 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
updateHookTypesDev();
return updateFormState(action, initialState, url);
return updateFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -4142,11 +4142,11 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
updateHookTypesDev();
return rerenderFormState(action, initialState, url);
return rerenderFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -4335,12 +4335,12 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
warnInvalidHookAccess();
mountHookTypesDev();
return mountFormState(action, initialState, url);
return mountFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -4533,12 +4533,12 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
warnInvalidHookAccess();
updateHookTypesDev();
return updateFormState(action, initialState, url);
return updateFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down Expand Up @@ -4731,12 +4731,12 @@ if (__DEV__) {
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
currentHookNameInDev = 'useFormState';
warnInvalidHookAccess();
updateHookTypesDev();
return rerenderFormState(action, initialState, url);
return rerenderFormState(action, initialState, permalink);
};
}
if (enableAsyncActions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactInternalTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export type Dispatcher = {
useFormState?: <S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
) => [S, (P) => void],
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function useOptimistic<S, A>(
function useFormState<S, P>(
action: (S, P) => Promise<S>,
initialState: S,
url?: string,
permalink?: string,
): [S, (P) => void] {
resolveCurrentlyRenderingComponent();
return [initialState, unsupportedDispatchFormState];
Expand Down