Guest User

Untitled

a guest
Dec 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. class Public extends React.Component {
  4. state = {
  5. message: ""
  6. }
  7.  
  8. componentDidMount() {
  9. fetch('/public').then(response => {
  10. if (response.ok) return response.json();
  11. throw new Error("Network response was not OK.");
  12. })
  13. .then(response => this.setState({ message: response.message }))
  14. .catch(error => this.setState({ message: error.message }));
  15. }
  16.  
  17. render() {
  18. return (
  19. <p>{this.state.message}</p>
  20. );
  21. }
  22. }
  23.  
  24. export default Public;
Add Comment
Please, Sign In to add comment