Pattern for syncing up multiple Refs in React [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Yes Refs aren't super preferable but sometimes you still need them.
So I have come up with a pattern (probably somebody already does this) to make sure I have multiple Refs ready.
class App extends Component
divOnePromise = new Promise(resolve => this.divOneResolve = resolve);
divTwoPromise = new Promise(resolve => this.divTwoResolve = resolve);
async componentDidMount()
const divOne = await this.divOnePromise;
const divTwo = await this.divTwoPromise;
console.log("refs synced", divOne, divTwo);
render()
return (
<div>
<div ref=this.divOneResolve>One</div>
<div ref=this.divTwoResolve>Two</div>
</div>
);
Would love some feedback!
javascript functional-programming react.js promise
closed as off-topic by Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher May 14 at 15:56
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher
add a comment |Â
up vote
1
down vote
favorite
Yes Refs aren't super preferable but sometimes you still need them.
So I have come up with a pattern (probably somebody already does this) to make sure I have multiple Refs ready.
class App extends Component
divOnePromise = new Promise(resolve => this.divOneResolve = resolve);
divTwoPromise = new Promise(resolve => this.divTwoResolve = resolve);
async componentDidMount()
const divOne = await this.divOnePromise;
const divTwo = await this.divTwoPromise;
console.log("refs synced", divOne, divTwo);
render()
return (
<div>
<div ref=this.divOneResolve>One</div>
<div ref=this.divTwoResolve>Two</div>
</div>
);
Would love some feedback!
javascript functional-programming react.js promise
closed as off-topic by Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher May 14 at 15:56
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Yes Refs aren't super preferable but sometimes you still need them.
So I have come up with a pattern (probably somebody already does this) to make sure I have multiple Refs ready.
class App extends Component
divOnePromise = new Promise(resolve => this.divOneResolve = resolve);
divTwoPromise = new Promise(resolve => this.divTwoResolve = resolve);
async componentDidMount()
const divOne = await this.divOnePromise;
const divTwo = await this.divTwoPromise;
console.log("refs synced", divOne, divTwo);
render()
return (
<div>
<div ref=this.divOneResolve>One</div>
<div ref=this.divTwoResolve>Two</div>
</div>
);
Would love some feedback!
javascript functional-programming react.js promise
Yes Refs aren't super preferable but sometimes you still need them.
So I have come up with a pattern (probably somebody already does this) to make sure I have multiple Refs ready.
class App extends Component
divOnePromise = new Promise(resolve => this.divOneResolve = resolve);
divTwoPromise = new Promise(resolve => this.divTwoResolve = resolve);
async componentDidMount()
const divOne = await this.divOnePromise;
const divTwo = await this.divTwoPromise;
console.log("refs synced", divOne, divTwo);
render()
return (
<div>
<div ref=this.divOneResolve>One</div>
<div ref=this.divTwoResolve>Two</div>
</div>
);
Would love some feedback!
javascript functional-programming react.js promise
asked May 9 at 8:24
Yeater
61
61
closed as off-topic by Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher May 14 at 15:56
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher
closed as off-topic by Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher May 14 at 15:56
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." â Sam Onela, Stephen Rauch, Toby Speight, Dannnno, Graipher
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05
add a comment |Â
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05
1
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
â Dannnno
May 14 at 15:05