Skip to main content

Posts

Showing posts from February, 2019

Difference between React State and Props

Before jumping to state vs props we have to compare a React component with a javascript plain function. Let me define a React component & a plain javascript function side by side. class DummyComponent extends React.Component { render () { return <div>Hey</div> } } const DummyFunction = () => console.log('Hey') We defined a React component named  DummyComponent  and returned a  div containing text  Hey  similarly, we defined a function named  DummyFunction and output  Hey  to the console. Isn’t they look a lot similar ? they both generate the same output write  Hey  to the output the only difference between the two is the React component going to render a div with text  Hey where the function going to output  Hey  on the console. So we now Know that React components are very similar to Plain Javascript functions. Let’s take a look at  State . React Component State A state in React Component is its own local state, the state cannot be