Ray Kholodovsky - Here is an error from trying ...

Here is an error from trying to do a simple react context implementation and no ts errors yet tsci error, followed by a different error on refresh. Next I will try to redo the code to look more like the tsci react context doc and see if this persists.
Execution Error: Eval compiled js error for "index.tsx": Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
@tscircuit/eval@0.0.417
@tscircuit/core@0.0.813
Error: Eval compiled js error for "index.tsx": Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
at h2 (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:390:687)
at async lu (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:394:828)
at async h2 (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:390:467)
at async lu (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:394:828)
at async Object.executeWithFsMap (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:416:2782)
Execution Error: Eval compiled js error for "index.tsx": Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
@tscircuit/eval@0.0.417
@tscircuit/core@0.0.813
Error: Eval compiled js error for "index.tsx": Minified React error #321; visit https://react.dev/errors/321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
at h2 (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:390:687)
at async lu (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:394:828)
at async h2 (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:390:467)
at async lu (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:394:828)
at async Object.executeWithFsMap (blob:http://localhost:3020/0ffc8d5c-1476-4c38-8739-5470f5650aea:416:2782)
No description
No description
9 Replies
Ray Kholodovsky
Ray KholodovskyOP•2mo ago
Also, I think the current iteration of these docs got too complex or too "down some rabbit hole of one particular usage scenario" https://docs.tscircuit.com/guides/typescript-guide/using-react-context-to-avoid-prop-drilling I would love a working demo/ example of the simplest possible case, which is what I'm trying to do: tldr as I understand it is import { createContext } from 'react'; export const MoleculeContext = createContext<ReturnType<typeof calculateMolecule> | null>(null); wrap <MoleculeContext.Provider value={moleculeResult}> around <board ... and then in the higher up usage: import { useContext } from 'react'; import { MoleculeContext } from "@molecule-templates/src/MoleculeBuilder"; const molDef = useContext(MoleculeContext); that's pretty much the code I have above that shouldn't be erroring in tsci, but is.
Using React Context to Avoid Prop-Drilling | tscircuit docs
React Context is a powerful tool for sharing data across deeply nested components without having to pass props through every level of the tree. When building TypeScript-powered circuit design tools, context lets you centralize configuration and provide well-typed data to any component that needs it.
Seve
Seve•2mo ago
yea i think youre usage is correct
Ray Kholodovsky
Ray KholodovskyOP•2mo ago
and would need to do that across separate files to truly replicate my usage so yeah the current tsci error is
Execution Error: Eval compiled js error for "index.tsx": Cannot read properties of null (reading 'useContext')
@tscircuit/eval@0.0.417
Error: Eval compiled js error for "index.tsx": Cannot read properties of null (reading 'useContext')
at h2 (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:390:687)
at async lu (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:394:828)
at async h2 (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:390:467)
at async lu (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:394:828)
at async Object.executeWithFsMap (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:416:2782)
Execution Error: Eval compiled js error for "index.tsx": Cannot read properties of null (reading 'useContext')
@tscircuit/eval@0.0.417
Error: Eval compiled js error for "index.tsx": Cannot read properties of null (reading 'useContext')
at h2 (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:390:687)
at async lu (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:394:828)
at async h2 (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:390:467)
at async lu (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:394:828)
at async Object.executeWithFsMap (blob:http://localhost:3020/f2253d1c-32e2-43b4-9692-c795976d1268:416:2782)
Seve
Seve•2mo ago
oh actually you might have an issue https://react.dev/errors/321
Minified React error #321 – React
The library for web and native user interfaces
Seve
Seve•2mo ago
or oh ok cannot read properties of null- that means your context isn't set
Ray Kholodovsky
Ray KholodovskyOP•2mo ago
hmmm.... I have
return (
<MoleculeContext.Provider value={moleculeResult}>
<board >

</board>
</MoleculeContext.Provider>
return (
<MoleculeContext.Provider value={moleculeResult}>
<board >

</board>
</MoleculeContext.Provider>
which fundamentally matches my understanding of where it's supposed to be set. and moleculeResult is already calculated in functions above otherwise we would have no molecule 🙂 so again to my point, this example seems overly verbose and I don't know whether I have to do it that way or if it should be fine my way. Hence, req for doc and demo of minimum working example
No description
Ray Kholodovsky
Ray KholodovskyOP•2mo ago
oh. I'm wrapping <board> with the context provider but I'm trying to access the context from outside the <Molecule component. Perhaps that's why the context is not reachable. I wil look into it.
Seve
Seve•2mo ago
yes there should be a working example at the bottom as well, i think it's pretty similar. There's an object defined (in your case it'll be computed) and the child components use it
Ray Kholodovsky
Ray KholodovskyOP•2mo ago
yeah I'm looking at the bottom example under Key Takeaways and I suspect the gem I need is somewhere in there. Working on figuring it out.

Did you find this page helpful?