Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Programming

    19. Уроки Node.js. Безопасный Путь к Файлу в fs и path.

    Beginners

    The Ultimate Guide to Using GitHub Pages

    Beginners

    Web Usability Essentials

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Tuesday, September 9
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / React / React Lessons / React Lesson 2: Homework Assignment
    JavaScript

    React Lesson 2: Homework Assignment

    Ilia DzhiubanskiyBy Ilia DzhiubanskiyNovember 1, 2019Updated:January 8, 2020No Comments2 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    React Lesson 2: Homework Assignment
    Hopefully, all's going well!
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    artwork depicting stylized React logo
    Hopefully, all’s going well!

    Let’s check our home task. The main reason of using React lies in the ability to create components based on your functionality set, i.e. to divide the whole app into small independent parts. In our case, we need to make comments our independent component. It will also be great to practice the skill of creating as many stateless components as possible. One of the examples in this scenario is the comment.js file.

    import React from 'react'  
    import PropTypes from 'prop-types';
      
    function Comment(props) {  
        const { comment: { text, user } } = props  
        return (  
            <div>  
                <p>{text}</p>  
                <b>by {user}</b>  
            </div>  
        )  
    }  
      
    export default Comment 
    

    CommentList.js

    import React, { Component } from 'react'  
    import PropTypes from 'prop-types';
    import Comment from './Comment'  
      
    class CommentList extends Component {  
        state = {  
            isOpen: false  
        }  
      
        render() {  
            const { comments } = this.props  
            if (!comments || !comments.length) return <h3>no comments yet</h3>  
            const { isOpen } = this.state  
            const commentItems = comments.map(comment => <li key = {comment.id}><Comment comment = {comment}/></li>)  
            const body = isOpen ? <ul>{commentItems}</ul> : null  
            const linkText = isOpen ? 'close comments' : 'show comments'  
            return (  
                <div>  
                    <a href="#" onClick = {this.toggleOpen}>{linkText}</a>  
                    {body}  
                </div>  
            )  
        }  
      
        toggleOpen = (ev) => {  
            ev.preventDefault()  
            this.setState({  
                isOpen: !this.state.isOpen  
            })  
        }  
    }  
      
    export default CommentList 
    

    Our file named Articles.js will change in the following way:

    import React, { Component } from 'react'  
    import CommentList from './CommentList' //added
        
      class Article extends Component {  
          state = {  
      
          render() {  
    //    const article = this.props.article  //deleted
    //    const { article } = this.props  //deleted
    //    const { article: { title, text } } = props  //deleted
     	const { article: { title, text, comments } } = this.props //added  
              const { isOpen } = this.state  
    //   	const body = isOpen ? <section>{ article.text }</section> : null  //deleted
         	const body = isOpen ? <section>{ text } <CommentList comments = {comments} /></section> : null  //added
        
              return (  
                  <div>  
                 	{/*<h1 onClick = {this.toggleOpen}>{ article.title }</h1>  //deleted */}
                 	<h1 onClick = {this.toggleOpen}>{ title }</h1>  //added
                      {body}  
                  </div>  
              )
    

    This is how our home task coding will look like. You can download the file with the updated project from our repository or just copy it. Our next assignments will continue in this file.

    Read More:  React Lesson 3: Exploring the React Component Lifecycle

    a mockup web page of our blog at blog.blog.soshace.com

    React lessons can be viewed here: https://blog.soshace.com/category/javascript/react/react-lessons/

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ilia Dzhiubanskiy

      Related Posts

      Streamlining Resource Allocation for Enhanced Project Success

      December 18, 2024

      Conducting Effective Post-Project Evaluations: A Guide

      December 16, 2024

      Strategies for Keeping Projects on Track and Meeting Deadlines

      December 10, 2024
      Leave A Reply Cancel Reply

      You must be logged in to post a comment.

      Stay In Touch
      • Facebook
      • Twitter
      • Pinterest
      • Instagram
      • YouTube
      • Vimeo
      Don't Miss
      Node.js September 18, 2020

      Node.js Lesson 4: NPM Package Structure

      Hey everyone, this lesson is going to be all about the node package and its structure. We will understand what the package.json file actually is and its characteristics. We will learn what does those mighty properties inside package.json denotes and why they are important. Let’s start.

      Minimize Downtime by Creating a Health-check for Your NodeJS Application

      September 23, 2020

      How to Architect a Node.Js Project from Ground Up?

      December 19, 2019

      TOP 5 Books about Silicon Valley that Blew Up the Internet

      February 26, 2019

      Categories

      • AI & Automation
      • Angular
      • ASP.NET
      • AWS
      • B2B Leads
      • Beginners
      • Blogs
      • Business Growth
      • Case Studies
      • Comics
      • Consultation
      • Content & Leadership
      • CSS
      • Development
      • Django
      • E-commerce & Retail
      • Entrepreneurs
      • Entrepreneurship
      • Events
      • Express.js
      • Facebook Ads
      • Finance & Fintech
      • Flask
      • Flutter
      • Franchising
      • Funnel Strategy
      • Git
      • GraphQL
      • Home Services Marketing
      • Influencer & Community
      • Interview
      • Java
      • Java Spring
      • JavaScript
      • Job
      • Laravel
      • Lead Generation
      • Legal & Compliance
      • LinkedIn
      • Machine Learning
      • Marketing Trends
      • Medical Marketing
      • MSP Lead Generation
      • MSP Marketing
      • NestJS
      • Next.js
      • Node.js
      • Node.js Lessons
      • Paid Advertising
      • PHP
      • Podcasts
      • POS Tutorial
      • Programming
      • Programming
      • Python
      • React
      • React Lessons
      • React Native
      • React Native Lessons
      • Recruitment
      • Remote Job
      • SaaS & Tech
      • SEO & Analytics
      • Soshace
      • Startups
      • Swarm Intelligence
      • Tips
      • Trends
      • Vue
      • Wiki
      • WordPress
      Top Posts

      Programming Patterns. Strategy, Observer, Iterator

      Programming February 8, 2017

      Maximizing B2B Leads: A Guide to Account-Based Marketing

      B2B Leads December 10, 2024

      Facilisi Nullam Vehicula Ipsum Arcu Cursus Vitae Congue

      Trends January 28, 2020

      Essential Steps to Identify and Validate Your Business Ideas

      Entrepreneurship November 30, 2024

      Subscribe to Updates

      Get The Latest News, Updates, And Amazing Offers

      About Us
      About Us

      Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

      7901 4th St N, Suite 28690
      Saint Petersburg, FL 33702-4305
      Phone: 1(877)SOSHACE

      Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
      Our Picks
      Entrepreneurship

      Essential Strategies for Building a Robust Entrepreneurial Network

      Programming

      1. Express.js Lessons. Basics and Middleware. Part 1.

      Programming

      Effective Strategies for Utilizing Frameworks in Web Development

      Most Popular

      Centralize The Configuration of Services With Spring Cloud Config

      Java

      Implementing Machine Learning in Web Applications with Python and TensorFlow

      Flask

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      SEO & Analytics
      © 2025 Soshace Digital.
      • Home
      • About
      • Services
      • Contact Us
      • Privacy Policy
      • Terms & Conditions

      Type above and press Enter to search. Press Esc to cancel.