Skip to content

Instantly share code, notes, and snippets.

@ohac
Created December 20, 2020 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohac/f4fd73d5daf25f3984a2829ab19c215e to your computer and use it in GitHub Desktop.
Save ohac/f4fd73d5daf25f3984a2829ab19c215e to your computer and use it in GitHub Desktop.
React component for Monacard API
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