<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: GAURAV YADAV</title>
    <description>The latest articles on DEV Community by GAURAV YADAV (@dvgy).</description>
    <link>https://dev.to/dvgy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F292568%2F4352d50b-3fa7-45a3-97a4-4b444310e9e7.png</url>
      <title>DEV Community: GAURAV YADAV</title>
      <link>https://dev.to/dvgy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dvgy"/>
    <language>en</language>
    <item>
      <title>Something wrong with my state in react ?? </title>
      <dc:creator>GAURAV YADAV</dc:creator>
      <pubDate>Wed, 01 Apr 2020 06:44:23 +0000</pubDate>
      <link>https://dev.to/dvgy/something-wrong-with-my-state-in-react-i77</link>
      <guid>https://dev.to/dvgy/something-wrong-with-my-state-in-react-i77</guid>
      <description>&lt;p&gt;This is what i am trying to do : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;" Every time the GET new Quote button is clicked it flips click between true/false, like flipping a lightswich on and off. Every time the newQuote property on  gets a new value, the QuoteBox component rerenders. Every time the component rerenders, it calls fetch in componentDidMount " *&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Please someone help me to runmy code properly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/random-quote-machine-fl6tc"&gt;Here is my code on sandbox:&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created this inside index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Parent extends React.Component {
 constructor(props) {
   super(props);
   this.state = {
     click: false
   };
 }

 render() {
   return (
     &amp;lt;&amp;gt;
       &amp;lt;QuoteBox newQuote={this.state.click} /&amp;gt;
       &amp;lt;button onClick={() =&amp;gt; this.setState({ click: !this.state.click })}&amp;gt;
         Get new quote
       &amp;lt;/button&amp;gt;
     &amp;lt;/&amp;gt;
   );
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I created this inside App.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button onClick={() =&amp;gt; this.setState({ click: !this.state.click })} 
        className="btn btn-primary"
        id="new-quote"
        &amp;gt;
        NEW QUOTE{this.props.newQuote}
&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>react</category>
    </item>
    <item>
      <title>Cannot add class but elements are already added to the DOM</title>
      <dc:creator>GAURAV YADAV</dc:creator>
      <pubDate>Sun, 15 Dec 2019 04:22:50 +0000</pubDate>
      <link>https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-198</link>
      <guid>https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-198</guid>
      <description>&lt;p&gt;Hey I am trying to add an active class to searchResult HTML using JavaScript.&lt;/p&gt;

&lt;p&gt;I try to search for recipe in search bar and results are displayed as it is shown in image.&lt;br&gt;
Search Result&lt;br&gt;
&lt;a href="https://i.stack.imgur.com/vWj4m.jpg"&gt;https://i.stack.imgur.com/vWj4m.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I click on a recipe from the search list I want to add a background color to the currently selected recipe(click on the recipe) using function resultHighlight()&lt;/p&gt;

&lt;p&gt;function resultHighlight() is being called in the controller and produces an error. Since the HTML is already added(after a search query is fired) by function renderRecipe() then why it is unable to find href id and producing error ?&lt;/p&gt;

&lt;p&gt;//Function to add background color&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export const resultHighlight = id =&amp;gt; {&lt;br&gt;
document&lt;br&gt;
.querySelector(&lt;/code&gt;&lt;code&gt;a[href="#${id}"]&lt;/code&gt;&lt;code&gt;)&lt;br&gt;
.classList.add("results__link--active");&lt;br&gt;
};&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Error Image&lt;br&gt;
&lt;a href="https://i.stack.imgur.com/m372A.jpg"&gt;https://i.stack.imgur.com/m372A.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: I tried console logging follwoing part and it returns null.&lt;/p&gt;

&lt;p&gt;`document.querySelector(a[href="#${id}"])&lt;/p&gt;

&lt;p&gt;//OUTPUT: null`&lt;/p&gt;

&lt;p&gt;JavaScript has already added HTML by a function (Search result)&lt;/p&gt;

&lt;p&gt;See the full question here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-2km8"&gt;https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-2km8&lt;/a&gt;&lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Cannot add class but elements are already added to the DOM</title>
      <dc:creator>GAURAV YADAV</dc:creator>
      <pubDate>Sat, 14 Dec 2019 16:40:25 +0000</pubDate>
      <link>https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-2km8</link>
      <guid>https://dev.to/dvgy/cannot-add-class-but-elements-are-already-added-to-the-dom-2km8</guid>
      <description>&lt;p&gt;Hey I am trying to add an active class to searchResult HTML using Javascript.&lt;/p&gt;

&lt;p&gt;I try to search for recipe in search bar and results are displayed as it is shown in image.&lt;/p&gt;

&lt;p&gt;Search Result&lt;br&gt;
&lt;a href="https://i.stack.imgur.com/vWj4m.jpg"&gt;https://i.stack.imgur.com/vWj4m.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I click on a recipe from the search list I want to add a background color to the currently selected recipe(click on the recipe) using function resultHighlight()&lt;/p&gt;

&lt;p&gt;function resultHighlight() is being called in the controller and produces an error. Since the HTML is already added(after a search query is fired) by function renderRecipe() then why it is unable to find href id and producing error ?&lt;/p&gt;

&lt;p&gt;//Function to add background color &lt;/p&gt;

&lt;p&gt;export const resultHighlight = id =&amp;gt; {&lt;br&gt;
  document&lt;br&gt;
    .querySelector(&lt;code&gt;a[href="#${id}"]&lt;/code&gt;)&lt;br&gt;
    .classList.add("results__link--active");&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;Error Image&lt;br&gt;
&lt;a href="https://i.stack.imgur.com/m372A.jpg"&gt;https://i.stack.imgur.com/m372A.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE: I tried console logging follwoing part and it returns null.&lt;/p&gt;

&lt;p&gt;document.querySelector(&lt;code&gt;a[href="#${id}"]&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;//OUTPUT: null&lt;/p&gt;

&lt;p&gt;JavaScript has already added HTML by a function (Search result)&lt;/p&gt;

&lt;p&gt;//Function to add search result on UI&lt;/p&gt;

&lt;p&gt;const renderRecipe = recipe =&amp;gt; {&lt;br&gt;
      const markup = &lt;code&gt;&lt;br&gt;
      &amp;lt;li&amp;gt;&lt;br&gt;
        &amp;lt;a class="results__link results__link--active"  href="#${recipe.recipe_id}"&amp;gt;&lt;br&gt;
          &amp;lt;figure class="results__fig"&amp;gt;&lt;br&gt;
          &amp;lt;img src="${recipe.image_url}" alt="${recipe.title}"&amp;gt;&lt;br&gt;
          &amp;lt;/figure&amp;gt;&lt;br&gt;
            &amp;lt;div class="results__data"&amp;gt;&lt;br&gt;
             &amp;lt;h4 class="results__name"&amp;gt;${reduceRecipeTitle(recipe.title)}&amp;lt;/h4&amp;gt;&lt;br&gt;
                 &amp;lt;p class="results__author"&amp;gt;${recipe.publisher}&amp;lt;/p&amp;gt;&lt;br&gt;
            &amp;lt;/div&amp;gt;&lt;br&gt;
          &amp;lt;/a&amp;gt;&lt;br&gt;
       &amp;lt;/li&amp;gt;&lt;/code&gt;;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  elements.searchResList.insertAdjacentHTML("beforeend", markup);
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
