Created
December 20, 2020 14:36
-
-
Save ohac/f4fd73d5daf25f3984a2829ab19c215e to your computer and use it in GitHub Desktop.
React component for Monacard API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
class Monacard extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
url: null | |
} | |
} | |
componentDidMount() { | |
const name = this.props.name | |
fetch('https://card.mona.jp/api/card_detail?assets=' + name) | |
.then(res => res.json()) | |
.then( | |
(result) => { | |
const url = result.details[0].imgur_url | |
this.setState({url: url}) | |
}, | |
(error) => { | |
// TODO | |
}) | |
} | |
render() { | |
return ( | |
<img src={this.state.url} alt='' width='224' height='320' /> | |
) | |
} | |
} | |
export default Monacard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment