I am trying to send props to my class component. So in the parent component:
<Child contract={_contract}/>
I sent the props like this.
And in child component in one of my functions, I am calling the prop like this:
class Mint extends React.Component {
constructor() {
super();
this.state = {
balance: [],
};
}
async componentDidMount() {
await axios.get(`https://api.cronoscan.com/api?module=stats&action=tokensupply&contractaddress=${ADDRESS}&apikey=${apikey}`)
.then(output => {
this.setState({
balance: output.data.result
})
})
}
mintNft = async () => {
var _mintAmount = Number(document.querySelector("[name=amount]").value);
var mintRate = Number(await this.props.contract.methods.cost().call());
var totalAmount = mintRate * _mintAmount;
this.props.contract.methods.mint(
localStorage
.getItem('walletAddress'), _mintAmount)
.send({
from: JSON.parse(localStorage.getItem('walletAddress')),
value: String(totalAmount)
});
}
render() {
const { balance } = this.state;
const { nftdata } = this.state;
return (
<button onClick={mintNft}>Mint</button>
);
}
}
export default Mint;
but it gives an error Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'props')
Waiting for your answers. Thanks.