React - passing and receiving value between 2 components

0 votes
20 views
added May 7 in React by lcjr First Warrant Officer (11,930 points)
edited May 7 by lcjr
//passing similarPropsData value
function SimilarPropertiesComponent({ listingProperties }) {
  const [similarPropsData, setData] = useState([]);

//JSX
return (
<React.Fragment>
  //need to pass this
  {similarPropsData.length > 0 && (
    <div className="detail-similar-prop" id="similar-listing-expiry">
....


//receiving similarPropsData
class MainComponent extends React.Component {
  static contextType = AuthContext;
  
  constructor(props) {
  super(props);
  this.columnSideRef = React.createRef();
  this.transactionRef = React.createRef();
  this.stickyRef = React.createRef();
  this.state = {
  width: 0,
  openShortlistModal: false,
  shortlistCount: 0,
  nearbyAmenities: {},
  transcBtn: true,
  headerChange: false,
  similarPropsData: [], // Add similarPropsData state
};

//JSX
render() {
  const { data, listingProperties, similarPropsData } = this.props;

{similarPropsData && similarPropsData.length > 0 && (
  <span>View Similar Properties</span>
)}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...