Repository: expo/expo
File: docs/ui/components/Snippet/blocks/SnackInline.tsx (TypeScript)

Code before:
  const getSelectedDocsVersion = () => {
    const { version } = context as PageApiVersionContextType;
    return version === 'latest' ? LATEST_VERSION : version;
  };

  // Get a SDK version that Snack will understand. `latest` and `unversioned`
  // are meaningless to Snack so we filter those out and use `LATEST_VERSION` instead
  const getSnackSdkVersion = () => {
    let version = getSelectedDocsVersion();
    if (version === 'unversioned') {
      version = LATEST_VERSION;
    }

    return version.replace('v', '');
  };

  const getExamplesPath = () => {
    return `${document.location.origin}/static/examples/${getSelectedDocsVersion()}`;
  };

  const getCode = () => {
    const code = contentRef.current ? contentRef.current.textContent || '' : '';
    return code.replace(/%%placeholder-start%%.*%%placeholder-end%%/g, '');
  };

  const codeLanguage = findPropInChildren(children as ReactElement, 'className')?.split('-')[1];

  return (
    <Snippet className="flex flex-col mb-3 prose-pre:!m-0 prose-pre:!border-0">
      <SnippetHeader title={label || 'Example'} Icon={SnackLogo}>
        <form action={SNACK_URL} method="POST" target="_blank" className="contents">
          <input type="hidden" name="platform" value={defaultPlatform || DEFAULT_PLATFORM} />
          <input type="hidden" name="name" value={label || 'Example'} />
          <input type="hidden" name="dependencies" value={dependencies.join(',')} />
          <input type="hidden" name="sdkVersion" value={getSnackSdkVersion()} />
          {platforms && (
            <input type="hidden" name="supportedPlatforms" value={platforms.join(',')} />
          )}
          {isReady && (
            <input
              type="hidden"
              name="files"
              value={JSON.stringify(
                getSnackFiles({
                  templateId,
                  code: getCode(),
                  files,
                  baseURL: getExamplesPath(),
                  codeLanguage,
                })
              )}

Review comment (bug):
```suggestion
  const prismBlockClassName = findPropInChildren(children as ReactElement, 'className');
  const codeLanguage = prismBlockClassName ? prismBlockClassName.split('-')[1] : 'jsx';
```

Nit, let's add a fallback to `jsx` if something goes wrong with the detection.

Code after:
  const getSelectedDocsVersion = () => {
    const { version } = context as PageApiVersionContextType;
    return version === 'latest' ? LATEST_VERSION : version;
  };

  // Get a SDK version that Snack will understand. `latest` and `unversioned`
  // are meaningless to Snack so we filter those out and use `LATEST_VERSION` instead
  const getSnackSdkVersion = () => {
    let version = getSelectedDocsVersion();
    if (version === 'unversioned') {
      version = LATEST_VERSION;
    }

    return version.replace('v', '');
  };

  const getExamplesPath = () => {
    return `${document.location.origin}/static/examples/${getSelectedDocsVersion()}`;
  };

  const getCode = () => {
    const code = contentRef.current ? contentRef.current.textContent || '' : '';
    return code.replace(/%%placeholder-start%%.*%%placeholder-end%%/g, '');
  };

  const prismBlockClassName = findPropInChildren(children as ReactElement, 'className');
  const codeLanguage = prismBlockClassName ? prismBlockClassName.split('-')[1] : 'jsx';

  return (
    <Snippet className="flex flex-col mb-3 prose-pre:!m-0 prose-pre:!border-0">
      <SnippetHeader title={label || 'Example'} Icon={SnackLogo}>
        <form action={SNACK_URL} method="POST" target="_blank" className="contents">
          <input type="hidden" name="platform" value={defaultPlatform || DEFAULT_PLATFORM} />
          <input type="hidden" name="name" value={label || 'Example'} />
          <input type="hidden" name="dependencies" value={dependencies.join(',')} />
          <input type="hidden" name="sdkVersion" value={getSnackSdkVersion()} />
          {platforms && (
            <input type="hidden" name="supportedPlatforms" value={platforms.join(',')} />
          )}
          {isReady && (
            <input
              type="hidden"
              name="files"
              value={JSON.stringify(
                getSnackFiles({
                  templateId,
                  code: getCode(),
                  files,
                  baseURL: getExamplesPath(),
                  codeLanguage,
                })