{"id":928,"date":"2024-05-08T09:19:00","date_gmt":"2024-05-08T07:19:00","guid":{"rendered":"https:\/\/programmier-workshops.de\/blog\/?p=928"},"modified":"2024-05-09T11:56:16","modified_gmt":"2024-05-09T09:56:16","slug":"lesson-understanding-react","status":"publish","type":"post","link":"https:\/\/programmier-workshops.de\/blog\/lesson-understanding-react\/","title":{"rendered":"Lesson: Understanding React"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/programmier-workshops.de\/blog\/lesson-understanding-react\/#Introduction_to_React_Framework\" >Introduction to React Framework<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/programmier-workshops.de\/blog\/lesson-understanding-react\/#Key_Components_and_Techniques_in_React\" >Key Components and Techniques in React<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/programmier-workshops.de\/blog\/lesson-understanding-react\/#Examples_with_Source_Code\" >Examples with Source Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/programmier-workshops.de\/blog\/lesson-understanding-react\/#Learning\" >Learning<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction_to_React_Framework\"><\/span>Introduction to React Framework<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">React is a powerful JavaScript library that has revolutionized the way developers build web applications. Created by Facebook in 2013, React makes it easier to create interactive user interfaces using components. It utilizes a declarative paradigm that makes code more predictable and easier to debug. Whether you&#8217;re building a small or large-scale application, React offers a flexible and efficient solution to enhance user experience.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Key_Components_and_Techniques_in_React\"><\/span>Key Components and Techniques in React<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">React&#8217;s architecture revolves around components, which can be thought of as reusable building blocks for your user interface. Here\u2019s a quick overview of the basic components and techniques used in React:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Components<\/strong>: These are the building blocks of any React application. They can be class-based or functional.\n<ul class=\"wp-block-list\">\n<li><strong>Functional Components<\/strong>: These are JavaScript functions that return elements representing a part of the UI.<\/li>\n\n\n\n<li><strong>Class Components<\/strong>: These are ES6 classes that extend from <code>React.Component<\/code> and can hold and manage local state.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>JSX (JavaScript XML)<\/strong>: JSX is a React extension that allows you to write HTML structures in the same file as JavaScript code. This makes the code easier to understand and maintain.<\/li>\n\n\n\n<li><strong>Props<\/strong>: Short for properties, props are a way of passing data from parent to child components. They are immutable, which means they cannot be changed by the child component.<\/li>\n\n\n\n<li><strong>State<\/strong>: Unlike props, the state is internal to the component and can change over time, usually as a result of user actions.<\/li>\n\n\n\n<li><strong>Hooks<\/strong>: Introduced in React 16.8, hooks allow you to use state and other React features without writing a class. <code>useState<\/code> and <code>useEffect<\/code> are among the most commonly used hooks.<\/li>\n\n\n\n<li><strong>Event Handling<\/strong>: React elements can handle events similar to handling events on DOM elements. These events are written in camelCase syntax.<\/li>\n\n\n\n<li><strong>Lifecycle Methods<\/strong>: In class components, lifecycle methods like <code>componentDidMount<\/code>, <code>componentDidUpdate<\/code>, and <code>componentWillUnmount<\/code> allow you to run code at particular times in the component&#8217;s lifecycle.<\/li>\n\n\n\n<li><strong>Context API<\/strong>: This provides a way to pass data through the component tree without having to pass props down manually at every level.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples_with_Source_Code\"><\/span>Examples with Source Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at some basic examples to understand these concepts better.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 1: Functional Component with Props<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Welcome(props) {\n  return &lt;h1>Hello, {props.name}&lt;\/h1>;\n}\n\n\/\/ Usage\n&lt;Welcome name=\"React\" \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 2: Class Component with State<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Counter extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = { count: 0 };\n  }\n\n  incrementCount = () => {\n    this.setState({ count: this.state.count + 1 });\n  };\n\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>{this.state.count}&lt;\/h1>\n        &lt;button onClick={this.incrementCount}>Increment&lt;\/button>\n      &lt;\/div>\n    );\n  }\n}\n\n\/\/ Usage\n&lt;Counter \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example 3: Using Hooks<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import React, { useState } from 'react';\n\nfunction Counter() {\n  const [count, setCount] = useState(0);\n\n  return (\n    &lt;div>\n      &lt;h1>{count}&lt;\/h1>\n      &lt;button onClick={() => setCount(count + 1)}>Increment&lt;\/button>\n    &lt;\/div>\n  );\n}\n\n\/\/ Usage\n&lt;Counter \/><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Learning\"><\/span>Learning<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/react.dev\/reference\/react\">https:\/\/react.dev\/reference\/react<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/react.dev\/learn\/thinking-in-react\">https:\/\/react.dev\/learn\/thinking-in-react<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to React Framework React is a powerful JavaScript library that has revolutionized the way developers build web applications. Created by Facebook in 2013, React makes it easier to create interactive user interfaces using components. It utilizes a declarative paradigm that makes code more predictable&hellip;<\/p>\n","protected":false},"author":1,"featured_media":939,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,3,33],"tags":[],"class_list":["post-928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-kurs","category-kurs-lesson"],"_links":{"self":[{"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/posts\/928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/comments?post=928"}],"version-history":[{"count":5,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/posts\/928\/revisions"}],"predecessor-version":[{"id":937,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/posts\/928\/revisions\/937"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/media\/939"}],"wp:attachment":[{"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/media?parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/categories?post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programmier-workshops.de\/blog\/wp-json\/wp\/v2\/tags?post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}