screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [ipAddress, setIpAddress] = useState(null); useEffect(() => { fetch('https://api.ipify.org?format=json') .then(response => response.json()) .then(data => setIpAddress(data.ip)) .catch(error => console.error(error)); }, []); return ( <div> <h3>React Js Get Client IP Address</h3> <div> {ipAddress && <p>Your IP address is: {ipAddress}</p>} {!ipAddress && <p>Loading...</p>} </div> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> div { background-color: #f2f2f2; border: 1px solid #ccc; padding: 10px; margin-bottom: 20px; } h3 { color: #333; font-size: 20px; margin-top: 0; } p { color: #666; font-size: 16px; margin: 0; padding: 5px 0; } </style> </body> </html>