Piplup
@piplup/rhf-adaptersmui-materialComponents

MuiRatingElement

A pre-integrated MuiRatingElement component for connecting MUI Rating to React Hook Form.

Import

import { MuiRatingElement } from "@piplup/rhf-adapters/mui-material";

Usage

"use client";import Stack from "@mui/material/Stack";import {  MuiButtonElement,  MuiRatingElement,} from "@piplup/rhf-adapters/mui-material";import { useForm } from "react-hook-form";export default function Page() {  const { control, handleSubmit } = useForm({    defaultValues: { rating: 3 },  });  return (    <form      onSubmit={handleSubmit((values) =>        alert(JSON.stringify(values, null, 2)),      )}    >      <Stack direction="column" spacing={2}>        <MuiRatingElement control={control} name="rating" />        <div>          <MuiButtonElement control={control} type="submit" variant="contained">            Submit          </MuiButtonElement>        </div>      </Stack>    </form>  );}
"use client";import Stack from "@mui/material/Stack";import {  MuiRatingElement,  MuiButtonElement,} from "@piplup/rhf-adapters/mui-material";import { FormContainer } from "@piplup/rhf-core";export default function Page() {  return (    <FormContainer      defaultValues={{ rating: 3 }}      onSubmit={(values) => alert(JSON.stringify(values, null, 2))}    >      <Stack direction="column" spacing={2}>        <MuiRatingElement name="rating" />        <div>          <MuiButtonElement type="submit" variant="contained">Submit</MuiButtonElement>        </div>      </Stack>    </FormContainer>  );}

Props

Prop

Type

MuiRatingElement supports props of the MUI Rating component, along with additional adapter-specific props. For a complete list of available Rating properties, refer to the MUI API documentation.

The ref is forwarded to the underlying <Rating /> component.

Notes

  • For custom rating UIs, build on useMuiRatingAdapter.

See also

On this page