0
votes

I have below wrapper kind of conditional wrapper and i am trying to replace with the below condition with conditional wrapper

 render: (text) => {
    return (
      <ConditionalWrapper
        condition={isCheckedFn?.(text)}
        wrapper={(ch) => (
          <Badge count={<CheckCircleFilled style={{ color: 'green' }} />}>{ch}</Badge>
        )}
      >
        <ConditionalWrapper
          condition={isSelectable}
          wrapper={(ch) => (
            <Button type="link" onClick={() => action(ch)}>
              {ch}
            </Button>
          )}
        >
          {isEqual(searchedColumn, fieldName) && !isEmpty(searchText) ? (
            <Highlighter
              highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
              searchWords={[searchText]}
              autoEscape
              textToHighlight={text.toString()}
            />
          ) : (
            text
          )}
        </ConditionalWrapper>
      </ConditionalWrapper>
    );
  }

and the below is conditional wrapper component

const ConditionalWrapper = ({ condition, wrapper, children }) =>
  condition ? wrapper(children) : children;

export default ConditionalWrapper;

and then i am trying to replace below rendering highlighter with conditional wrapper

{isEqual(searchedColumn, fieldName) && !isEmpty(searchText) ? (
            <Highlighter
              highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
              searchWords={[searchText]}
              autoEscape
              textToHighlight={text.toString()}
            />
          ) : (
            text
          )}

and after that it looks like this

render: (text) => {     
    return (
      <ConditionalWrapper
        condition={isCheckedFn?.(text)}
        wrapper={(ch) => (
          <Badge count={<CheckCircleFilled style={{ color: 'green' }} />}>{ch}</Badge>
        )}
      >
        <ConditionalWrapper
          condition={isSelectable}
          wrapper={(ch) => (
            <Button type="link" onClick={() => action(ch)}>
              {ch}
            </Button>
          )}
        >
         <ConditionalWrapper  // getting error in this conditional wrapper
            condition={isEqual(searchedColumn, fieldName) && !isEmpty(searchText)}
            wrapper={(text) =>
              (<Highlighter
              highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
              searchWords={[searchText]}
              autoEscape
              textToHighlight={text.toString()}
            />)
            }
            text
           />
        </ConditionalWrapper>
      </ConditionalWrapper>
    );
  },

with this code getting an error like as below

Error: ConditionalWrapper(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

I don't know what I am doing wrong with above code could any one please let me know where i am doing wrong and is this proper way to use that conditional wrapper.

Many thanks in advance

1
is there anything not clear - Enigma State

1 Answers

1
votes

I think this because third ConditionalWrapper has no children (I guess it is a typo? As text is passed as prop). Something like this should work

<ConditionalWrapper
  condition={isEqual(searchedColumn, fieldName) && !isEmpty(searchText)}
  wrapper={(ch) => (
    <Highlighter
      highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
      searchWords={[searchText]}
      autoEscape
      textToHighlight={ch.toString()}
    />
  )}
>
  {text}
</ConditionalWrapper>