CodeSampleX

サンプル

react 19.0.0: useDeferredValue

検証済みサンプル — npm react 19.0.0: useDeferredValue. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: react package.json exports useDeferredValue and…

sha256:86a9448a6582db4e03bd2e69d517d87955ac77cd3c92ddeb444fbba7f290cddb

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-29

ケース

HOW
ゴール
verify useDeferredValue in pkg:npm/react@19.0.0
パッケージ
シンボル
  • useDeferredValue
環境
node 22.23.2
作成日
2026-08-29T14:49:28Z

コントラクト

  1. react package.json exports useDeferredValue and version 19.0.0
  2. react exports useDeferredValue as a function matching the named and default exports
  3. useDeferredValue throws an invalid hook call error when invoked outside component rendering context
  4. useDeferredValue delegates value and initialValue to the active hook dispatcher
  5. useDeferredValue supports single-argument invocation passing undefined as initialValue to the dispatcher
  6. SearchResults component executes useDeferredValue inside custom dispatcher and renders React element

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify useDeferredValue in pkg:npm/react@19.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react@19.0.0
Demonstrate these symbols/APIs:
  - useDeferredValue
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:e3289e06a180139ffcf21dacfe8052d5c28c26c8727d10a25b2cfdae23389286","contract":["react package.json exports useDeferredValue and version 19.0.0","react exports useDeferredValue as a function matching the named and default exports","useDeferredValue throws an invalid hook call error when invoked outside component rendering context","useDeferredValue delegates value and initialValue to the active hook dispatcher","useDeferredValue supports single-argument invocation passing undefined as initialValue to the dispatcher","SearchResults component executes useDeferredValue inside custom dispatcher and renders React element"],"goal":"verify useDeferredValue in pkg:npm/react@19.0.0","kind":"HOW","packages":["pkg:npm/react@19.0.0"],"schemaVersion":1,"symbols":["useDeferredValue"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react@19.0.0"],"schemaVersion":1,"subject":"pkg:npm/react@19.0.0","symbols":["useDeferredValue"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-use-deferred-value",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-use-deferred-value",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react": "19.0.0"
      }
    },
    "node_modules/react": {
      "version": "19.0.0",
      "resolved": "https://registry.npmjs.org/react/-/react-19.0.0.tgz",
      "integrity": "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-use-deferred-value",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "react": "19.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify useDeferredValue in pkg:npm/react@19.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react@19.0.0"
  ],
  "symbols": [
    "useDeferredValue"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
src/index.js
import React, { useDeferredValue } from 'react';

/**
 * Component demonstrating useDeferredValue for deferring a search query update.
 *
 * @param {object} props
 * @param {string} props.query - Current search query.
 * @param {string} [props.initialQuery] - Optional initial deferred value for first render in React 19.
 * @returns {object} React element with deferred query value.
 */
export function SearchResults({ query, initialQuery }) {
  const deferredQuery = useDeferredValue(query, initialQuery);
  return React.createElement('div', { 'data-deferred': deferredQuery }, deferredQuery);
}

/**
 * Runs a hook function within a custom dispatcher context.
 *
 * @param {Function} callback - Function executing hook calls.
 * @param {object} dispatcher - Custom React dispatcher implementation.
 * @returns {any} Result of callback.
 */
export function withCustomDispatcher(callback, dispatcher) {
  const internals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
  const previousDispatcher = internals.H;
  try {
    internals.H = dispatcher;
    return callback();
  } finally {
    internals.H = previousDispatcher;
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { createRequire } from 'node:module';
import React, { useDeferredValue } from 'react';
import { SearchResults, withCustomDispatcher } from '../src/index.js';

const require = createRequire(import.meta.url);

// Contract 1: react package.json exports useDeferredValue and version 19.0.0
{
  const pkgJsonPath = require.resolve('react/package.json');
  assert.ok(fs.existsSync(pkgJsonPath));
  const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
  assert.strictEqual(pkgJson.name, 'react');
  assert.strictEqual(pkgJson.version, '19.0.0');
  assert.strictEqual(pkgJson.exports['.']['default'], './index.js');
}

// Contract 2: react exports useDeferredValue as a function matching the named and default exports
{
  assert.strictEqual(React.version, '19.0.0');
  assert.strictEqual(typeof React.useDeferredValue, 'function');
  assert.strictEqual(typeof useDeferredValue, 'function');
  assert.strictEqual(React.useDeferredValue, useDeferredValue);
}

// Contract 3: useDeferredValue throws an invalid hook call error when invoked outside component rendering context
{
  assert.throws(
    () => {
      useDeferredValue('test-value');
    },
    {
      name: 'TypeError',
      message: /Cannot read properties of null/
    }
  );
}

// Contract 4: useDeferredValue delegates value and initialValue to the active hook dispatcher
{
  let recordedCall = null;
  const mockDispatcher = {
    useDeferredValue(value, initialValue) {
      recordedCall = { value, initialValue };
      return initialValue !== undefined ? initialValue : value;
    }
  };

  const result = withCustomDispatcher(() => {
    return useDeferredValue('updated-term', 'initial-term');
  }, mockDispatcher);

  assert.deepStrictEqual(recordedCall, {
    value: 'updated-term',
    initialValue: 'initial-term'
  });
  assert.strictEqual(result, 'initial-term');
}

// Contract 5: useDeferredValue supports single-argument invocation passing undefined as initialValue to the dispatcher
{
  let recordedCall = null;
  const mockDispatcher = {
    useDeferredValue(value, initialValue) {
      recordedCall = { value, initialValue };
      return value;
    }
  };

  const result = withCustomDispatcher(() => {
    return useDeferredValue('current-input');
  }, mockDispatcher);

  assert.deepStrictEqual(recordedCall, {
    value: 'current-input',
    initialValue: undefined
  });
  assert.strictEqual(result, 'current-input');
}

// Contract 6: SearchResults component executes useDeferredValue inside custom dispatcher and renders React element
{
  const mockDispatcher = {
    useDeferredValue(value, initialValue) {
      return initialValue || value;
    }
  };

  const rendered = withCustomDispatcher(() => {
    return SearchResults({ query: 'deferred-search', initialQuery: 'placeholder' });
  }, mockDispatcher);

  assert.strictEqual(React.isValidElement(rendered), true);
  assert.strictEqual(rendered.type, 'div');
  assert.strictEqual(rendered.props['data-deferred'], 'placeholder');
  assert.strictEqual(rendered.props.children, 'placeholder');
}

console.log('All useDeferredValue contract tests passed.');

オリジンシーダー

匿名