Exemple
react 18.3.1: useCallback
Échantillon vérifié pour npm react 18.3.1: useCallback. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:3d3de7493f5963a8b48b2a319d86e41876e2942773f000edec9a9f74bb4f999f
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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-27 |
Cas
HOW- Objectif
- verify react.useCallback in pkg:npm/react@18.3.1
- Paquets
- Symboles
-
- react.useCallback
- Environnement
- node 22.23.2
- Créé
- 2026-08-27T21:15:44Z
Contrat
- react package.json declares export mappings for client and react-server entries at version 18.3.1
- react exports useCallback as a function on the default client runtime interface
- react useCallback throws a TypeError when invoked outside an active component render dispatcher
- react useCallback delegates setup callback and dependencies to the active ReactCurrentDispatcher
- react useCallback supports empty dependency arrays and omitted dependencies passing them to the dispatcher
- react react-server entry points to shared-subset which requires experimental channel in version 18.3.1
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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 react.useCallback in pkg:npm/react@18.3.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/react@18.3.1
Demonstrate these symbols/APIs:
- react.useCallback
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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.
{"case":{"caseId":"case:sha256:f57c43a39243442355deee09c711c198cf2207cffd603d2c12e163b492dcaeee","constraints":{"executionContext":"node"},"contract":["react package.json declares export mappings for client and react-server entries at version 18.3.1","react exports useCallback as a function on the default client runtime interface","react useCallback throws a TypeError when invoked outside an active component render dispatcher","react useCallback delegates setup callback and dependencies to the active ReactCurrentDispatcher","react useCallback supports empty dependency arrays and omitted dependencies passing them to the dispatcher","react react-server entry points to shared-subset which requires experimental channel in version 18.3.1"],"goal":"verify react.useCallback in pkg:npm/react@18.3.1","kind":"HOW","packages":["pkg:npm/react@18.3.1"],"schemaVersion":1,"symbols":["react.useCallback"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","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@18.3.1"],"schemaVersion":1,"subject":"pkg:npm/react@18.3.1","symbols":["react.useCallback"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-react-use-callback",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-react-use-callback",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"react": "18.3.1"
}
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"license": "MIT"
},
"node_modules/loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
"license": "MIT",
"dependencies": {
"js-tokens": "^3.0.0 || ^4.0.0"
},
"bin": {
"loose-envify": "cli.js"
}
},
"node_modules/react": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"license": "MIT",
"dependencies": {
"loose-envify": "^1.1.0"
},
"engines": {
"node": ">=0.10.0"
}
}
}
}
{
"name": "sample-react-use-callback",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"dependencies": {
"react": "18.3.1"
}
}
{
"schemaVersion": 1,
"goal": "verify react.useCallback in pkg:npm/react@18.3.1",
"kind": "HOW",
"packages": [
"pkg:npm/react@18.3.1"
],
"symbols": [
"react.useCallback"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';
import React from 'react';
const require = createRequire(import.meta.url);
// Contract 1: react package.json declares export mappings for client and react-server entries at version 18.3.1
{
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, '18.3.1');
assert.strictEqual(pkgJson.exports['.']['default'], './index.js');
assert.strictEqual(pkgJson.exports['.']['react-server'], './react.shared-subset.js');
}
// Contract 2: react exports useCallback as a function on the default client runtime interface
{
assert.strictEqual(typeof React.useCallback, 'function');
assert.strictEqual(React.version, '18.3.1');
}
// Contract 3: react useCallback throws a TypeError when invoked outside an active component render dispatcher
{
const internals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
assert.ok(internals && typeof internals === 'object');
assert.strictEqual(internals.ReactCurrentDispatcher.current, null);
assert.throws(
() => {
React.useCallback(() => {});
},
{
name: 'TypeError'
}
);
}
// Contract 4: react useCallback delegates setup callback and dependencies to the active ReactCurrentDispatcher
{
const internals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
let receivedCall = null;
const mockReturn = () => 'memoized_function';
internals.ReactCurrentDispatcher.current = {
useCallback(callback, deps) {
receivedCall = { callback, deps };
return mockReturn;
}
};
try {
const callbackFn = () => 42;
const deps = ['item1', 100, true];
const result = React.useCallback(callbackFn, deps);
assert.strictEqual(result, mockReturn);
assert.ok(receivedCall !== null);
assert.strictEqual(receivedCall.callback, callbackFn);
assert.strictEqual(receivedCall.deps, deps);
} finally {
internals.ReactCurrentDispatcher.current = null;
}
}
// Contract 5: react useCallback supports empty dependency arrays and omitted dependencies passing them to the dispatcher
{
const internals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
const receivedCalls = [];
internals.ReactCurrentDispatcher.current = {
useCallback(callback, deps) {
receivedCalls.push({ callback, deps });
return callback;
}
};
try {
const fn1 = () => 1;
const fn2 = () => 2;
// Without dependencies argument
const res1 = React.useCallback(fn1);
assert.strictEqual(res1, fn1);
assert.strictEqual(receivedCalls.length, 1);
assert.strictEqual(receivedCalls[0].callback, fn1);
assert.strictEqual(receivedCalls[0].deps, undefined);
// With empty dependencies array
const res2 = React.useCallback(fn2, []);
assert.strictEqual(res2, fn2);
assert.strictEqual(receivedCalls.length, 2);
assert.strictEqual(receivedCalls[1].callback, fn2);
assert.deepStrictEqual(receivedCalls[1].deps, []);
} finally {
internals.ReactCurrentDispatcher.current = null;
}
}
// Contract 6: react react-server entry points to shared-subset which requires experimental channel in version 18.3.1
{
const pkgJsonPath = require.resolve('react/package.json');
const pkgDir = path.dirname(pkgJsonPath);
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
const reactServerEntry = path.join(pkgDir, pkgJson.exports['.']['react-server']);
assert.ok(fs.existsSync(reactServerEntry));
assert.throws(
() => {
require(reactServerEntry);
},
(err) => {
return err instanceof Error && /experimental channels/.test(err.message);
}
);
}
console.log('All react.useCallback contract tests passed.');
Seeder d'origine
anonyme