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

[Docs]: action request method #9891

Closed
0r0loo opened this issue Jan 12, 2023 · 2 comments · Fixed by #9893
Closed

[Docs]: action request method #9891

0r0loo opened this issue Jan 12, 2023 · 2 comments · Fixed by #9893
Labels

Comments

@0r0loo
Copy link

0r0loo commented Jan 12, 2023

Describe what's incorrect/missing in the documentation

https://reactrouter.com/en/main/components/form#mutation-submissions

<Route
  path="/projects/:id"
  element={<Project />}
  loader={async ({ params }) => {
    return fakeLoadProject(params.id);
  }}
  action={async ({ request, params }) => {
    switch (request.method) {
      case "put": {
        let formData = await request.formData();
        let name = formData.get("projectName");
        return fakeUpdateProject(name);
      }
      case "delete": {
        return fakeDeleteProject(params.id);
      }
      default: {
        throw new Response("", { status: 405 });
      }
    }
  }}
/>;

request.method value is lower case. ex) get, post, delete ...

but

real is upper case ex) GET, POST, DELETE ...
image

my react-router-dom version is "react-router-dom": "^6.4.1",

export const adminDetailAction = async ({ request, params }) => {
  console.log('-> request', request);
  console.log('-> request.method', request.method);
  console.log('-> request.formData', await Utils.convertFormDataToObject(request));
  console.log('-> params', params);

  if ((request.method as FormMethod) === 'patch') {
    console.log('patch');
  }
};
  const onDeleteAdminHandler = useCallback(() => {
    submit(null, { action: `/management/admin/${params.adminId}`, method: 'delete' });
  }, [params.adminId, submit]);

  const onPatchAdminHandler = useCallback(() => {
    submit(null, { action: `/management/admin/${params.adminId}`, method: 'patch' });
  }, [params.adminId, submit]);
    <Form>
        <RowTable rows={tableRows} data={tableData} />
        <Stack
          direction={'row'}
          spacing={2}
          sx={{
            width: '100%',
            justifyContent: 'center',
            marginTop: '20px',
          }}
        >
          <Button variant={'contained'} onClick={onDeleteAdminHandler} color={'grey1'}>
            삭제
          </Button>
          <Button variant={'contained'} onClick={onPatchAdminHandler} color={'green'}>
            수정
          </Button>
        </Stack>
      </Form>

I am not good at English, so please understand.
thank you

@0r0loo 0r0loo added the docs label Jan 12, 2023
@0r0loo
Copy link
Author

0r0loo commented Jan 12, 2023

image

node v16.17.0

image

Is the capital letter correct? Is it lowercase?

@machour
Copy link
Contributor

machour commented Jan 12, 2023

Thanks for the bug report.

  • For a <form method=""> it's lowercase, and only "get" and "post" are supported.
  • For a <Form method=""> it's lowercase, and all methods are supported.
  • Request.method is always uppercase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants