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