useFormState fix: action -> target (#27309)

I mixed these attributes up in
https://github.com/facebook/react/pull/27302
This commit is contained in:
Andrew Clark
2023-08-29 22:17:15 -04:00
committed by GitHub
parent ddff504695
commit 2fba484cd0
2 changed files with 5 additions and 5 deletions
@@ -354,7 +354,7 @@ describe('ReactFlightDOMForm', () => {
// @gate enableFormActions
// @gate enableAsyncActions
it("useFormState can change the action's target with the `permalink` argument", async () => {
it('useFormState can change the action URL with the `permalink` argument', async () => {
const serverAction = serverExports(function action(prevState) {
return {state: prevState.count + 1};
});
@@ -386,7 +386,7 @@ describe('ReactFlightDOMForm', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.textContent).toBe('Count: 1');
expect(form.target).toBe('/permalink');
expect(form.action).toBe('http://localhost/permalink');
});
// @gate enableFormActions
@@ -427,6 +427,6 @@ describe('ReactFlightDOMForm', () => {
const span = container.getElementsByTagName('span')[0];
expect(span.textContent).toBe('Count: 1');
expect(form.target).toBe('/permalink');
expect(form.action).toBe('http://localhost/permalink');
});
});
+2 -2
View File
@@ -575,12 +575,12 @@ function useFormState<S, P>(
dispatch.$$FORM_ACTION = (prefix: string) => {
// $FlowIgnore[prop-missing]
const metadata: ReactCustomFormAction = boundAction.$$FORM_ACTION(prefix);
// Override the target URL
// Override the action URL
if (permalink !== undefined) {
if (__DEV__) {
checkAttributeStringCoercion(permalink, 'target');
}
metadata.target = permalink + '';
metadata.action = permalink + '';
}
return metadata;
};