Im trying to render the output of the polkadot browser extension but i'm getting this error Uncaught (in promise) Error: Objects are not valid as a React child (found: object with keys {address, meta, type}). If you meant to render a collection of children, use an array instead.
I see that it wants me to use an array (or a map?) but i'm unsure of how to implement this
Any ideas?
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';
import {
web3Accounts,
web3Enable,
web3FromAddress,
web3ListRpcProviders,
web3UseRpcProvider
} from '@polkadot/extension-dapp';
class UserComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
allInjected: [],
accountsInfo: []
};
}
async componentDidMount() {
this.handleButtonClick();
}
handleButtonClick = () => {
const getExtensionInfo = async () => {
const allInjected = await web3Enable('test');
const allAccounts = await web3Accounts();
//const account = allInjected;
//const info = address;
this.setState({
allInjected,
allAccounts
});
};
getExtensionInfo();
};
render() {
const allInjected = this.state.allAccounts?.map((a, i) => (
<li key={i} className="list-group-item">{a}</li>
));
const allAccounts = this.state.allAccounts?.map((a, i) => (
<li key={i} className="list-group-item">{a}</li>
));
return (
<div>
<h1>A user</h1>
<p>{allInjected}</p>
<h1>{allAccounts}</h1>
<button onClick={this.handleButtonClick}>Get Info</button>
</div>
);
}
}
ReactDOM.render(
<React.StrictMode>
<UserComponent />
</React.StrictMode>,
document.getElementById('root')
);
reportWebVitals();
Your rendering is wrong, try to replace
{a}by{a.login}something like this: