Pattern for syncing up multiple Refs in React [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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!







share|improve this question











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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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
















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!







share|improve this question











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
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 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












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!







share|improve this question











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!









share|improve this question










share|improve this question




share|improve this question









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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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




    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















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?