{"id":3194,"date":"2018-01-08T20:56:37","date_gmt":"2018-01-08T15:26:37","guid":{"rendered":"https:\/\/code4developers.com\/?p=3194"},"modified":"2018-01-08T20:56:37","modified_gmt":"2018-01-08T15:26:37","slug":"react-hello-world-and-jsx","status":"publish","type":"post","link":"https:\/\/code4developers.com\/react-hello-world-and-jsx\/","title":{"rendered":"React: Hello World and JSX"},"content":{"rendered":"<p>This is a typical Hello World implementation in React in JSX file. It shows one of two ways you can write components, and how you pass data to a components.<!--more--><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"atomic\">import React, { Component } from 'react';\r\nimport ReactDOM from 'react-dom';\r\n\r\nclass App extends Component {\r\n  render() {\r\n  return (\r\n    &lt;h1&gt;Hello {props.name}&lt;\/h1&gt;\r\n  )\r\n  }\r\n}\r\nReactDOM.render(&lt;App name=\"world\"\/&gt;, document.getElementById('root'));<\/pre>\n<p>Most React Components are written as classes Extending from the React.Component class, and the only method a component have to implement is \u201crender\u201d. It returns either a new component or markup.<\/p>\n<p>One side note: a component have to return <span class=\"underline\">one<\/span> root node. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"atomic\">&lt;!-\u2014 It can't return: --&gt;\r\n&lt;h1&gt;&lt;\/h1&gt;\r\n&lt;p&gt;&lt;\/p&gt;\r\n\r\n&lt;!-\u2014 But it can return --&gt;\r\n\r\n&lt;div&gt;\r\n   &lt;h1&gt;&lt;\/h1&gt;\r\n   &lt;p&gt;&lt;\/p&gt;\r\n&lt;\/div&gt;<\/pre>\n<h2 id=\"jsx\" class=\"blogroll-item__title\">JSX<\/h2>\n<p>JSX is the syntax we use to define markup with React. It combines JavaScript code and markup together in a very flexible and powerful way and is without doubt my favorite thing about React. Everything you use in JSX that isn\u2019t Javascript code, is technically components. All HTML tags are implemented as Components in React. For example the h2-tag is a h2 component inside the React package, with the appropriate params defined to an HTML attribute; note: they are not always the same though.<\/p>\n<p>Everything that you wrap in HTML tags (either self-closing or not) are components and everything inside curly braces are JavaScript code.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"atomic\">import react from 'react'\r\nconst Comp = () =&gt;\r\n    &lt;div&gt;\r\n        &lt;Header title=\"Hello World\"\/&gt;\r\n  &lt;Menu \/&gt;\r\n  &lt;Main&gt;\r\n      &lt;Router&gt;\r\n        &lt;\/Main&gt;\r\n        &lt;Footer\/&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>That would be a common starting point for a simple React app.<\/p>\n<p>I personally think that JSX is the first templating system I have seen that is powerful, without adding a lot of syntax that isn\u2019t plain JavaScript and HTML. Most other ways to template I have seen almost turn it into a language of its own that let you combine code and markup.<\/p>\n<p>The great thing about this is that almost everyone gets it straight away.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a typical Hello World implementation in React in JSX file. It shows one of two ways you can write components, and how you pass data to a components.<\/p>\n","protected":false},"author":7,"featured_media":3183,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[93],"tags":[95,98,94,97],"powerkit_post_featured":[],"class_list":{"0":"post-3194","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"tag-create-react-app","9":"tag-jsx","10":"tag-react","11":"tag-react-demo"},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/12\/react_2.png?fit=375%2C375&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8NAi4-Pw","jetpack-related-posts":[{"id":14480,"url":"https:\/\/code4developers.com\/angular-custom-elements\/","url_meta":{"origin":3194,"position":0},"title":"Angular Custom Elements: Creating Reusable Components with Angular","author":"Yatendrasinh Joddha","date":"April 19, 2023","format":false,"excerpt":"Angular Custom Elements allow you to create reusable components that can be used in non-Angular applications. Custom Elements are a powerful feature that can help you share code across multiple projects and platforms. In this article, we'll take a closer look at Angular Custom Elements and show you how to\u2026","rel":"","context":"In &quot;Angular&quot;","block_context":{"text":"Angular","link":"https:\/\/code4developers.com\/category\/angular\/"},"img":{"alt_text":"Angular Custom Elements","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/04\/Custom-elements.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/04\/Custom-elements.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/04\/Custom-elements.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/04\/Custom-elements.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/04\/Custom-elements.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":14686,"url":"https:\/\/code4developers.com\/unlocking-the-power-of-react-hooks\/","url_meta":{"origin":3194,"position":1},"title":"Unlocking the Power of React Hooks: A Comprehensive Guide with Examples","author":"Yatendrasinh Joddha","date":"October 15, 2023","format":false,"excerpt":"In the ever-evolving world of web development, React has been a game-changer. It simplifies building interactive and dynamic user interfaces. With React, you can create components, manage states, and handle side effects seamlessly. But as React evolves, so do the best practices and techniques for building applications. One significant improvement\u2026","rel":"","context":"In &quot;React&quot;","block_context":{"text":"React","link":"https:\/\/code4developers.com\/category\/react\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2023\/10\/React-icon.svg_-1-e1697396875978.png?fit=250%2C217&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3208,"url":"https:\/\/code4developers.com\/redux-example\/","url_meta":{"origin":3194,"position":2},"title":"Redux Example","author":"Arif Khoja","date":"January 22, 2018","format":false,"excerpt":"In case you missed out the basic for redux, you can Find it Here A Redux Store consists of a few different parts. You always have a single store, that uses either a single Reducer or Multiple Reducers (through Redux\u2019s CombineReducers method). And you dispatch actions to your reducers. (You\u2026","rel":"","context":"In &quot;React&quot;","block_context":{"text":"React","link":"https:\/\/code4developers.com\/category\/react\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2018\/01\/Redux.png?fit=312%2C244&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3189,"url":"https:\/\/code4developers.com\/what-react-is-and-how-it-is-different\/","url_meta":{"origin":3194,"position":3},"title":"What React is, and how it is different.","author":"Arif Khoja","date":"January 3, 2018","format":false,"excerpt":"We often compare React, Angular and Vue. I get why. But it isn\u2019t the best. Because both Vue and Angular are more complete solutions for building web apps, while React are just a library for dealing with the user interface part of it. And leave other things like communicating with\u2026","rel":"","context":"In &quot;React&quot;","block_context":{"text":"React","link":"https:\/\/code4developers.com\/category\/react\/"},"img":{"alt_text":"react","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/12\/react_2.png?fit=375%2C375&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":15211,"url":"https:\/\/code4developers.com\/react-hooks-guide-top-tips-for-optimizing-performance-in-your-react-applications\/","url_meta":{"origin":3194,"position":4},"title":"React Hooks Guide: Top Tips for Optimizing Performance in Your React Applications","author":"Arif Khoja","date":"April 2, 2024","format":false,"excerpt":"Boost the performance of your React applications with our top tips in the 'React Hooks Guide'.","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2024\/04\/image-1.jpg?fit=940%2C627&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2024\/04\/image-1.jpg?fit=940%2C627&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2024\/04\/image-1.jpg?fit=940%2C627&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2024\/04\/image-1.jpg?fit=940%2C627&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3182,"url":"https:\/\/code4developers.com\/react-blog-post-serieses-react-development\/","url_meta":{"origin":3194,"position":5},"title":"React: A blog post series about React development","author":"Arif Khoja","date":"December 30, 2017","format":false,"excerpt":"One of the first things I wrote down in my notebook as I was planning or trying to figure out if there was enough stuff to write about to do this site was a React introduction. I know React fairly well, and have been working full-time with it for quite\u2026","rel":"","context":"In &quot;React&quot;","block_context":{"text":"React","link":"https:\/\/code4developers.com\/category\/react\/"},"img":{"alt_text":"react","src":"https:\/\/i0.wp.com\/code4developers.com\/wp-content\/uploads\/2017\/12\/react_2.png?fit=375%2C375&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/comments?post=3194"}],"version-history":[{"count":2,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3194\/revisions"}],"predecessor-version":[{"id":3197,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/posts\/3194\/revisions\/3197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/media\/3183"}],"wp:attachment":[{"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/media?parent=3194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/categories?post=3194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/tags?post=3194"},{"taxonomy":"powerkit_post_featured","embeddable":true,"href":"https:\/\/code4developers.com\/wp-json\/wp\/v2\/powerkit_post_featured?post=3194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}