forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
31 lines (28 loc) · 919 Bytes
/
Button.js
File metadata and controls
31 lines (28 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from "react";
import PropTypes from "prop-types";
import Joi from "joi";
const style = {
background: "#800",
color: "#fff",
padding: 12,
};
export const Button = (props) => (
<button style={style}>{props.children}</button>
);
const FederatedButton = (props) => {
// specify prop schema
const schema = Joi.object({
children: [Joi.string(), Joi.array(), Joi.object()],
});
// memoize validation result
const { error } = React.useMemo(() => schema.validate(props), []);
if (error) {
// if it fails, return a fallback, or allow a fallback to be passed in
return <span>Validation Error</span>;
}
// if validation passes, expose the underlaying component.
// this wrapper also allows <button> to change without the consumer having to re-implement it.
// the wrapper can serve as an adapter
return <Button>{props.children}</Button>;
};
export default FederatedButton;