Background

I have been encountering a great many Pakistani nationalists on various platforms- Be it Twitter, Reddit or YouTube. Instead of wasting my time taking them on one by one; I have decided to…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A date with React Refs

I was beating all around and over the code. I needed my Async drop down using the cool react-select and redux-form to auto refresh with fresh values.

I knew it was something simple but fundamental, the reason why it felt terrible moving on without fixing it. I am also using redux-form.

class Parent extends React.Componet {

render() {

<FormSelect1 …props />

<FormSelect2 …props />

}

}

class FormSelect2 extends React.Component {

render() {

<div>

<SelectOptions ..props />

</div>

}

}

My requirement was for the SelectOptions component to refresh its dropdown list, based on the selection made in FormSelect1.

But the SelectOptions list was getting updated only on user interaction, rather than dynamically, because of which the user would see the old list and then the new list.

The SelectOptions is a third party component and it makes an async call to fetch a dropdown list. It exposed an interface to populate the list. This interface is an anonymous function which can be passed as a prop. I was passing this anonymous function as a prop from FormSelect2.

Here is a confession of the ignorant mistake I made, I put a ref on FormSelect2 and through that accessed the props of SelectOptions to invoke the anonymous function. <duh>. The above is a mistake because just executing the javascript function is not going inject the list into the dom element. I needed to access the particular dom element and the javascript function should be run by that particular dom element. If that makes sense!

Here is how I eventually fixed the issue.

So when FormSelect1 changes, the function loadMyStuff is run, which runs the function executeFnOnElement, which populates the options with the SelectOptions element.

Add a comment

Related posts:

Digital Marketing Services You Really Should Be Using For Your Business

The digital age has changed the way consumers make decisions and interact with businesses. We are currently living in the most connected time in human history, where family and friends have more…

Tribute by Children

3 Blessed be the God and Father of our Lord Jesus Christ, who according to His abundant mercy has begotten us again to a living hope through the resurrection of Jesus Christ from the dead, 4 to an…

From Porn to Divorce

While attempting to figure out if it was “ok”, by my moral standards, I didn’t particularly find any fault with it. I even used the Bible as a reference and, at that time, I didn’t really see…