React UI - 07 - Random Image Generator Giphy API

Size
4,193 Kb
Views
60,720

How do I make an react ui - 07 - random image generator giphy api?

What is a react ui - 07 - random image generator giphy api? How do you make a react ui - 07 - random image generator giphy api? This script and codes were developed by Xavier Martínez on 31 October 2022, Monday.

React UI - 07 - Random Image Generator Giphy API Previews

React UI - 07 - Random Image Generator Giphy API - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>React UI - 07 - Random Image Generator Giphy API</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="card"></div> <script src='https://npmcdn.com/[email protected]/dist/react.min.js'></script>
<script src='https://npmcdn.com/[email protected]/dist/react-dom.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

React UI - 07 - Random Image Generator Giphy API - Script Codes CSS Codes

body { margin: 0; font-family: sans-serif; font-size: 12px; background: #e2e1e0; text-align: center;
}
.btn-loadimg { border: 2px solid #00E676; background-color: #00E676; color: white; padding: 10px; margin: 10px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.btn-loadimg:hover { cursor: pointer; border: 2px solid #00E676; color: #00E676; background-color: white;
}
h1 { text-align: center; color: #00E676; text-shadow: 1px 1px 1px #00796B; padding: 20px; margin: 0;
}
#card { padding: 20px;
}
.card-item { background-color: #fff; color: #00E676; width: 320px; margin: 0 auto; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.card-item img { display: block;
}

React UI - 07 - Random Image Generator Giphy API - Script Codes JS Codes

'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var SEARCH_KEY = 'pug';
var RandomGif = function (_React$Component) { _inherits(RandomGif, _React$Component); function RandomGif(props) { _classCallCheck(this, RandomGif); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = { imageSrc: '' }; _this.loadImage = _this.loadImage.bind(_this); return _this; } RandomGif.prototype.componentDidMount = function componentDidMount() { this.loadImage(); }; RandomGif.prototype.loadImage = function loadImage() { var _this2 = this; var url = 'https://api.giphy.com/v1/gifs/random?tag=' + this.props.keyword + '&api_key=' + this.props.apiKey; fetch(url).then(function (response) { return response.json(); }).then(function (res) { return _this2.setState({ imageSrc: res.data.image_url }); }).catch(function (res) { console.log('ERROR: No image from API!'); }); }; RandomGif.prototype.render = function render() { return React.createElement( 'div', { className: 'card-item' }, React.createElement( 'h1', null, 'Random ' + this.props.keyword + ' image' ), React.createElement('img', { src: this.state.imageSrc, style: { width: "100%", maxHeight: "auto" } }), React.createElement( 'button', { onClick: this.loadImage, className: 'btn-loadimg' }, 'MOAR!' ) ); }; return RandomGif;
}(React.Component);
ReactDOM.render(React.createElement(RandomGif, { apiKey: 'afea92ac6eff442ba6fca79368717d0d', keyword: SEARCH_KEY }), document.getElementById('card'));
React UI - 07 - Random Image Generator Giphy API - Script Codes
React UI - 07 - Random Image Generator Giphy API - Script Codes
Home Page Home
Developer Xavier Martínez
Username xmjol
Uploaded October 31, 2022
Rating 3
Size 4,193 Kb
Views 60,720
Do you need developer help for React UI - 07 - Random Image Generator Giphy API?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Xavier Martínez (xmjol) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!