about summary refs log tree commit diff
path: root/src/view/com/util/NoSnippetWrapper.tsx
blob: fcf65824946a8bf51cff21f736587d2f02214005 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {type ViewProps} from 'react-native'
// @ts-expect-error untyped
import {unstable_createElement} from 'react-native-web'

import {isWeb} from '#/platform/detection'

interface Props extends ViewProps {
  enabled: boolean
}

/**
 * NoSnippetWrapper prevents search engines from displaying snippets of its content.
 *
 * If running on web and enabled, wraps children in a <div> with data-nosnippet attribute.
 * Otherwise, renders children directly.
 *
 * @param enabled - Whether to apply the data-nosnippet attribute.
 * @param viewProps - Additional props for the wrapper element.
 */
export function NoSnippetWrapper({enabled, ...viewProps}: Props) {
  if (isWeb && enabled) {
    return unstable_createElement('div', {
      ...viewProps,
      'data-nosnippet': '',
    })
  }

  return <>{viewProps.children}</>
}