Comments (4)
This is documented on these pages, depending on what you're looking to achieve:
- Passing props to a component
- Passing event handlers as props
- Sharing state between components
- Passing data deeply with context
The .bind
specific technique is briefly mentioned in the Legacy Component docs here, but createReactClass
is deprecated and will not be added to the new site. See the legacy site for createReactClass
docs.
from react.dev.
Nowhere in the documentation does it say.
For communication between two components that don't have a parent-child relationship, you can set up your own global event system. (Old React Docs said)
Is using a global event system not a good practice and only using context(or lifting state up) is best practice?
from react.dev.
Correct, the only way to do it safely with concurrent features today is to de-opt with useSyncExternalStore, which has limitation such as forcing fallbacks for existing content. We're aware this is a pain point, though we don't have any solutions to recommend until we build better support for it.
from react.dev.
Thank you. I found an example that uses useSyncExternal
, I'll check it out.
facebook/react#14988 (comment)
https://codesandbox.io/p/sandbox/hopeful-sara-fb970f?file=%2Fsrc%2Findex.js%3A1%2C1-47%2C1
I would be happy if React provided a built-in event emitter system like Angular, Vue. 😄
from react.dev.
Related Issues (20)
- Unpredicted behaviour in Online Code editor[Bug]:
- Hey
- [Bug]: "Referencing Values with Refs" ref illustration leads to sketchy site
- This page doesn’t exist. HOT 1
- [Suggestion]: Add some elaboration to the docs for TypeScript DOM events and Pure Functions
- ⚠Phishing Website Warning!!! There are phishing website links in the document. HOT 1
- [Bug]: photos in ref section of the tutorial are down
- [Suggestion]: shortcuts to localized sites?
- Not Found
- [Bug]: the hydrate-mismatch link seems not right HOT 4
- GENERATE_SOURCEMAP=false Issue HOT 1
- Worflow Automator Issues
- [Bug]: Excessive Requests for Page Data - Why Does This Happen?
- links to "use server" and "use client" docs are broken on directive page docs
- directives page is not found HOT 1
- 'use server' reference page does not exist in the doc HOT 1
- [Suggestion]: Add tsconfig.json update to React 19 upgrade guide HOT 8
- Use-server documentation URL broken HOT 2
- references/react-dom/components/button link in 20240425 blog post results to Not Found page
- [Typo]: No mention of isPending in return values of useActionState
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.dev.