Home > database >  How can I export the value of {this.props.price * this.state.quantity} so I could use it in a differ
How can I export the value of {this.props.price * this.state.quantity} so I could use it in a differ

Time:09-07

import React, {Component} from 'react';
import { dumpLogs } from './Utils.js';



class RecCard extends Component {
     state = {
         quantity: null
     }

     incrementNumber = () => {
         this.setState((prevState, prevProp) => {
             return {quantity : prevState.quantity  1}
         });
     }

     decrementNumber = () => {
         this.setState((prevState, prevProp) => {
            return {quantity : prevState.quantity -1}
            
         });
     }

    render() {
    dumpLogs(this.props);
    return(
        <div>
            <h3>{this.props.title}</h3>
            <h5>{this.props.price} PLN</h5>
            <span>{this.state.quantity}</span> &nbsp; 
            <span className='hidden'>{this.props.price * this.state.quantity}</span> 
            <button onClick={this.incrementNumber}> </button>
            <button onClick={this.decrementNumber} disabled={this.state.quantity <= null}>-
            </button>
        </div>

    )}
        
}



export default RecCard; 

CodePudding user response:

From what i can see, this is (most likely) a duplicate of This Post.
You should be able to export values using the export keyword. By assigning your this.props.price * this.state.quantity to a local variable and then exporting said variable (using export MaxPrice, or whatever you called that variable).

Cheers!

CodePudding user response:

Sounds logical but where should I assign it? Inside the RecCard class, before it or after? A 'this.' prefix afaik should be used only within a class, on the other hand as you can see the whole 'RecCard' component is exported here and I would like to export the aforementioned JSX expression separately as a variable.

  • Related