score:2
Accepted answer
According to Yup's documentation:
By default, the cast logic of string is to call toString on the value if it exists. empty values are not coerced (use ensure() to coerce empty values to empty strings).
In other words it calls toString()
on the select result which will be "[object Object]"
(i.e. it is a string). You can fix it by using strict()
(documentation here):
validationSchema={Yup.object().shape({
select: Yup.string()
.strict(true)
.required(" select Required")
})}
Of course then your select input will fail validation so you need to change it to something like this:
<Select
options={options}
value={options.find(({ label }) => label === values.select)}
onChange={value => setFieldValue("select", value.label)}
onBlur={() => setFieldTouched("select")}
/>
Source: stackoverflow.com
Related Query
- Why Yup string validation doesn't throw error when it's an object?
- Why does defineMessages from react-intl throw an error when passing in a object reference?
- Why does react hook throw the act error when used with fetch api?
- Object or String type conditional with yup validation
- Why does React throw an error when setState method used in a class constructor?
- React JS throw "TypeError: Cannot read property 'name' of undefined" error when i want to access object details
- Nextjs getStaticProps error when passing an object as prop instead of plain string
- React - proptypes validation - return Error doesnt work but throw does
- Why do I get an object error when using useEffect and setInterval in my React app?
- Getting the following error when creating React HOC: type is invalid -- expected string or a class/function but got: object
- Why do I get an authentication error when I pass an axios config object with an authorization token? MERN
- Why do I get this error (TypeError) when I loop through an object using react?
- why Leaflet throw me this Error when im renderin in react?
- Why does 'yield' throw an error when used twice in saga?
- Why does Typescript throw an error when typing Redux-saga call parameter - TS2339
- Why does the React hook useRef throw an error when used?
- Why is This React Code Unreachable When Its an Array But Works for a Single Object
- Why I don't see all the keys and values of an object when its keys are long strings?
- Validation using Yup to check string or number length
- Object is not extensible error when creating new attribute for array of objects
- Force ReactJS to throw real errors when propTypes validation fails?
- Error when creating new object from existing one using `...`: In this environment the sources for assign MUST be an object
- How to assign object validation in yup for react-select (single-select)
- Why is IE8 getting a script error when using Facebook's React.js
- Why I am getting this error message when I run react js project first time in my system?
- Why does React resolve undefined/boolean/null to string only when they are variables?
- Pass an object with JS throw new Error in node
- Why is npm react-scripts producing a syntax error when I run `npm run start`?
- Validation using Yup to check array length --> error if length === 1
- Why does jest-dom give the error "TypeError: expect(...).not.toBeVisible is not a function" when I use it
More Query from same tag
- How I can remove only one object in mongodb, not all objects matching the filter query?
- Firebase Error: Objects are not valid as a React child (found: object with keys {seconds, nanoseconds})
- why i am not able to use the default theme properties in makeStyle?
- Preloading images and audio with a progress bar in React
- React Pass history to a component defined in the Router
- Is there a better way of exporting multiple named functions in React?
- How to reuse action creators in react-redux?
- How to write an handleSubmit function to setState for multiple forms
- How to import more-vert icon in material-ui for react?
- Infinite scroll using redux and react
- Disable Material-UI production css classnames in React
- cache react component on router change
- How can I change the color of the active navbar item?
- Hangman game effect of setSolved() is delayed
- React: Child Component Filtering Parent Component Props
- How to render conditionally with styled-components?
- React JS make async call without componentdidmount()
- How to pass array dynamically in asyncBlurField redux-form?
- How activate the right button with onKeyPress (React JS)?
- How to stop auto re-render on components by using useEffect hook?
- Redux Thunk with Typescript
- Flowtype error with react: This type is incompatible with props of JSX Intrinsic
- How can I align my labels, input, and textarea on same line?
- MUI Chips as tags that can be selected (checkbox like behavior)
- Testing react-router v4 with Jest and Enzyme
- Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema
- Shopify Polaris: How to make an item active in ActionList?
- fill in a HTML table with all days of month and date table from postgresql (javascript)
- ES6 React istanbul No coverage information was collected, exit without writing coverage information
- Separate images in react-image-lightbox