Skip to content

Instantly share code, notes, and snippets.

@mdmoin7
Created April 27, 2019 04:52
Show Gist options
  • Save mdmoin7/309e0dd42dcfdcdb40ee9385bcf5feb0 to your computer and use it in GitHub Desktop.
Save mdmoin7/309e0dd42dcfdcdb40ee9385bcf5feb0 to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import { checkErrors } from './validation-service';
// import {Text} from 'react-native' // only for react-native app
class ShowErrors extends React.Component {
static propTypes = {
value: PropTypes.any,
validations: PropTypes.object,
display: PropTypes.bool
};
static defaultProps = {
display: false
};
listOfErrors() {
const { validations, value } = this.props;
const errors = checkErrors(value, validations);
console.log(errors);
return errors;
}
// use <Text> instead of <small> if using in react-native
render() {
if (!this.props.display) { return null; }
return (
<div>
{this.listOfErrors().map(
err => <small key={err}>{err}</small>
)}
</div>
);
}
}
export default ShowErrors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment