require('whatwg-fetch') require('./styles.scss') const React = require('react') const ReactDOM = require('react-dom') function fetchResources(url) { return new Promise((resolve, reject) => { fetch(url) .then(response => { return response.json() }) .then(json => { console.log('RESPONSE:', json) resolve(json) }) .catch(error => { reject(error) console.log('ERROR:', error) }) }) } class SmartTable extends React.Component { constructor(props) { super(props) this.state = { error: null, loading: false, items: [], } } async componentWillMount() { this.setState({ ...this.state, error: null, loading: true }) try { const news = await fetchResources(this.props.url) this.setState({ ...this.state, items: news, error: null, loading: false }) } catch (error) { this.setState({ ...this.state, error: error }) console.error('ERROR:', error) } } render() { return (
Sorry, we had an issue loading results, please try again in a few moments.
) } if (loading) { return (Loading...
) } const columns = Object.values(items[0].column_mappings) return ({col} | )}
---|