<?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: codabat</title>
    <description>The latest articles on DEV Community by codabat (@codabat).</description>
    <link>https://dev.to/codabat</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%2F408831%2F000d8aa7-4a06-44c2-a8bb-8abe29dc130f.png</url>
      <title>DEV Community: codabat</title>
      <link>https://dev.to/codabat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codabat"/>
    <language>en</language>
    <item>
      <title>Components (statess and statefull) and props</title>
      <dc:creator>codabat</dc:creator>
      <pubDate>Sun, 14 Jun 2020 19:06:40 +0000</pubDate>
      <link>https://dev.to/codabat/components-statess-and-statefull-and-props-7jn</link>
      <guid>https://dev.to/codabat/components-statess-and-statefull-and-props-7jn</guid>
      <description>&lt;p&gt;Hi everyone,&lt;br&gt;
After my presentation in the dedicated section, this is my first post.&lt;br&gt;
I decided to learn React as a web app development framework, along with nodejs.&lt;/p&gt;

&lt;p&gt;Right now, I'm studying a somewhat dated book.&lt;br&gt;
I got to the part dedicated to stateless and statefull components.&lt;br&gt;
Well, I don't understand if the book was made worse, or why the examples refer to a somewhat dated version of React. Strange that, however, the author's GitHub code is also different from that of the book.&lt;/p&gt;

&lt;p&gt;Below is an example of code displayed on the book:&lt;/p&gt;

&lt;p&gt;var ReactClass = createClass ({&lt;br&gt;
  render: function () {&lt;br&gt;
    console.log (this.props.isHidden)&lt;br&gt;
    return React.createElement ('h1', {className: 'header'}, this.props.isHidden || true, 'React Component');&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;const ReaComponentElement = React.createElement (ReactClass)&lt;br&gt;
consteagComponent = ReactDOM.render (reactionsComponentElement, document.getElementById ('react-application'))&lt;/p&gt;

&lt;p&gt;But note that console.log (this.props.isHidden) is always undefined.&lt;/p&gt;

&lt;p&gt;As you can see, the implementation is already an adaptation to what is reported in the book. The book uses React.createClass, a function that no longer exists and is no longer valid, I think, from ES6.&lt;br&gt;
So I had to add the addiction:&lt;br&gt;
const createClass = require ('create-react-class');&lt;br&gt;
which returns the function that allows you to create a class. But console.log ('read isHidden:', this.props.isHidden) is always undefined&lt;/p&gt;

&lt;p&gt;So I tried to transform the code like today, I think, it should be written correctly, as follows:&lt;/p&gt;

&lt;p&gt;the ReactClass class extends React.Component {&lt;br&gt;
   render () {&lt;br&gt;
     console.log ('read isHidden:', this.props.isHidden)&lt;br&gt;
     if (this.props.isHidden === 'true') {&lt;br&gt;
       returns null;&lt;br&gt;
     }&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; return React.createElement ('h1', {className: 'header', key: 'header'}, 'React Component')
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;ReactDOM.render (, document.getElementById ('react-application'))&lt;/p&gt;

&lt;p&gt;Now console.log ('read isHidden:', this.props.isHidden) is no longer undefined, but accepts the value passed as the property of the ReactClass component ().&lt;/p&gt;

&lt;p&gt;I don't understand what the author meant except that the rendering method can decide what to do.&lt;br&gt;
But in my opinion, a component based on this.props is a stateless component. What do you think?.&lt;br&gt;
Can you give me your opinion on what the author meant and if you agree on my conclusions?&lt;/p&gt;

&lt;p&gt;Somewhere I read that the author's approach would perhaps work if the props were to pass to the constructor. Is this true?&lt;/p&gt;

&lt;p&gt;I apologize for the stupid questions.&lt;/p&gt;

&lt;p&gt;Thanks so much.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
