Here is how I did it
import { object, string, mixed } from "yup"
const schema = object().shape({
attachment: mixed().test("fileSize", "The file is too large", (value) => {
if (!value.length) return true // attachment is optional
return value[0].size <= 2000000
}),
})
Related Contents:
- React Formik – Trigger validation only on form submit
- React formik form validation: How to initially have submit button disabled
- Async validation with Formik, Yup and React
- Conditional Validation in Yup
- Validation using Yup to check string or number length
- React Formik use submitForm outside
- Formik onSubmit function is not working on my code
- Formik – How to reset form after confirmation
- ReactJS: How to handle Image / File upload with Formik?
- How to use custom Input with Formik in React?
- React-datepicker with a Formik form
- Yup.when: “`NaN` (cast from the value `NaN`)”
- Why isn’t the Formik `touched` property being populated?
- How to combine multiple inline style objects?
- How to use callback with useState hook in react [duplicate]
- How to disable a button when an input is empty?
- Receiving “Attempted import error:” in react app
- How to submit a form using Enter key in react.js?
- What is the meaning of {…this.props} in Reactjs
- Component does not remount when route parameters change
- How to assign the correct typing to React.cloneElement when giving properties to children?
- When would bindActionCreators be used in react/redux?
- How to configure package.json to run eslint script
- Module not found: ‘redux’
- How to use generics in props in React in a functional component?
- If condition inside of map() React
- React: validateDOMNesting: #text cannot appear as a child of
- How to update meta tags in React.js?
- React Hooks – How do I implement shouldComponentUpdate?
- Blank page after running build on create-react-app
- TypeError during Jest’s spyOn: Cannot set property getRequest of # which has only a getter
- Before and After pseudo classes used with styled-components
- How do you make the ListHeaderComponent of a React Native FlatList sticky?
- How to minimize the size of webpack’s bundle?
- Multiple params with React Router
- Setting a checkbox “check” property in React
- How to get input text value on click in ReactJS
- In Material UI when do we use Input vs. TextField for building a form?
- Why does create-react-app creates both App.js and index.js?
- Using webpack aliases in mocha tests
- How to make create-react-app use npm instead of yarn?
- ReactJS findDOMNode and getDOMNode are not functions
- How to use the increment operator in React
- this.setState is undefined
- How to avoid `loaded two copies of React` error when developing an external component?
- React statics with ES6 classes
- Firestore to query by an array’s field value
- Pass object through Link in react router
- Module not found: Can’t resolve ‘bootstrap/dist/css/bootstrap-theme.css’ in ‘C:\react-form-validation-demo\src’
- React Router v4 routes not working