How to integrate if statement in react component


In my rails - react app, I want to hide an information from the product in a specific case. I tried to use if statement, but can’t get the result I am looking for. Here is what I did in my jsx view file.

function Product({hit}) {
  return (
      <div className = "h5">
      <div className = "">
        <Hits hitComponent={Weight} />

with that if statement

function Weight({hit}) {
  if (hit.weight = "") {
    return <p>No</p>;
    return <p>Yes {hit.weight}</p>;

I am getting as a result :

The name of the product
Followed with ‘Yes’ 20 times + I never get “No”

I am able to show the weight when

        <div className = "">

Any clue on what I am doing wrong ?

Hi there,

The HitsComponent prop is used for each result. That’s why it’s used 20 times.

But then I’m not sure if it’s what you were asking for :slight_smile: Can you try to build a test case with codeSandBox?