React - assign and update variable based on conditions

0 votes
35 views
added Mar 15 in React by lcjr First Warrant Officer (11,850 points)

Assigning listingType variable based on the conditions, you can use the equality operator (===) for comparison and update the variable accordingly. Here's how you can do it:

const { intent } = TestBuddyData.output.detect;
const occupancyType = TestBuddyData.output.detect.entities.occupancy_type;
let listingType = '';
if (occupancyType.is_buy) {
  listingType = 'sale';
} else if (occupancyType.is_rent) {
  listingType = 'rent';
}
if (intent.is_property_scouting_score > 7 && listingType) {
  const response = TestBuddyData.output.response.content;
  const newAnswers = [...buddyA, response];
  console.log(listingType);
  setBuddyAs(newAnswers);
  setCookie('buddy_a', newAnswers, { path: '/' });
} else {
  // Handle other cases if needed
}

 

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