Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. const Address = ({ provideApi }) => {
  2. const { address, setAddress, errAddress, seterrAddress, setAddressEv, isValid } = useAddress();
  3.  
  4. provideApi( {
  5. isValid,
  6. getAddress: () => address
  7. } );
  8.  
  9. return (
  10. <div>
  11. <label>
  12. Address:
  13. <input value={ address } onChange={ setAddressEv } type="text" />
  14. {
  15. errAddress ? <span className="invalid">invalid</span> : <span className="valid">valid</span>
  16. }
  17. </label>
  18.  
  19. <button onClick={ isValid }>OK</button>
  20.  
  21. </div>
  22. );
  23. }
  24.  
  25. const App = () => {
  26. let isShippingAddressValid, getShippingAddress, isBillingAddressValid, getBillingAddress;
  27.  
  28. const setShippingAddressApi = (api) => {
  29. ({ isValid: isShippingAddressValid, getAddress: getShippingAddress } = api);
  30.  
  31. };
  32. const setBillingAddressApi = (api) => {
  33. ({ isValid: isBillingAddressValid, getAddress: getBillingAddress } = api);
  34. };
  35.  
  36.  
  37. const isShippingAddressValidAlert = () => {
  38. alert( `isvalid: ${isShippingAddressValid()}` );
  39. };
  40.  
  41. const isBillingAddressValidAlert = () => {
  42. alert( `isvalid: ${isBillingAddressValid()}` );
  43. }
  44.  
  45. return (
  46. <div className="demoApp">
  47.  
  48. <h2>Shipping Address</h2>
  49. <Address provideApi={ setShippingAddressApi } />
  50.  
  51. <hr />
  52.  
  53. <h2>Billing Address</h2>
  54. <Address provideApi={ setBillingAddressApi } />
  55.  
  56. <button onClick={ isShippingAddressValidAlert }> Validate shipping and tell me if it's valid </button>
  57.  
  58. <button onClick={ isBillingAddressValidAlert }> Validate shipping and tell me if it's valid </button>
  59.  
  60.  
  61.  
  62. </div>
  63. );
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement