Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tag <ErrorMessage> Formik react Style

I would like to apply the style to Formik's tag for react. How can I do?

<ErrorMessage name="email"></ErrorMessage>

I try with component={Custom} but don't work.

I use Tailwindcss.

Thanks if you want to help me.

like image 904
Samuele B Avatar asked Sep 16 '25 07:09

Samuele B


2 Answers

To add a class to a React component, use className="theClass". Formik's ErrorMessage.component property takes a value of a custom component, e.g. component={Custom} as you have, or it can take an HTML container, e.g. component="div". Assuming this is not a Tailwind port to React, "div" is appropriate. Putting these two together, you can apply Tailwind-style invalid message styling thus:

<ErrorMessage name="emailAddress" component="div" className="text-red-500 text-xs italic" />
like image 141
sfuqua Avatar answered Sep 19 '25 01:09

sfuqua


<ErrorMessage name="field name" component="div" className="some classes" />

add "component" field for ErrorMessage component

like image 30
ნიკა ლომთაძე Avatar answered Sep 19 '25 01:09

ნიკა ლომთაძე