<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ framework - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ framework - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 28 May 2026 16:47:13 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/framework/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Understanding Modern Development Frameworks: A Guide for Developers and Technical Decision-makers ]]>
                </title>
                <description>
                    <![CDATA[ As a developer for over 20 years, I've seen firsthand how choosing the right framework can make or break a project. The term "framework" has become so broad that it's often misunderstood. Let's clear up the confusion and help you make better technica... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/understanding-modern-development-frameworks-guide-for-devs/</link>
                <guid isPermaLink="false">673cc307f6df251b434f7f90</guid>
                
                    <category>
                        <![CDATA[ Developer ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jesse Hall ]]>
                </dc:creator>
                <pubDate>Tue, 19 Nov 2024 16:55:35 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731968979425/412c6bc7-e717-481b-aa9e-4962c9687115.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As a developer for over 20 years, I've seen firsthand how choosing the right framework can make or break a project. The term "framework" has become so broad that it's often misunderstood. Let's clear up the confusion and help you make better technical decisions.</p>
<h2 id="heading-what-is-a-framework">What is a Framework?</h2>
<p>In terms of software development, a framework is a structured set of tools, libraries, and conventions that provides a foundation for building applications more efficiently by handling common functionalities so developers can focus on unique features.</p>
<p>A modern web application can combine multiple frameworks to handle different aspects of development efficiently:</p>
<ul>
<li><p>React with Tailwind CSS manages the user interface and styling.</p>
</li>
<li><p>FastAPI or Django with LangChain handle backend operations and AI functionality, while MongoDB acts as a memory store.</p>
</li>
</ul>
<p>These frameworks communicate through APIs and defined interfaces to work together—for example, a user interaction in the React front end can trigger an AI process through LangChain in the Python back end, which uses MongoDB Atlas Vector Search to retrieve relevant data and then display it back to the user with Tailwind CSS styles.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-the-framework-landscape-in-2024">The framework landscape in 2024</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-application-frameworks">Application frameworks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-ai-frameworks">AI frameworks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-web-frameworks">Web frameworks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-cssui-frameworks">CSS/UI frameworks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-testing-amp-infrastructure">Testing &amp; infrastructure</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-making-the-right-choice">Making the right choice</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-bottom-line">The bottom line</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-additional-resources">Additional resources</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-frequently-asked-questions-faq">Frequently asked questions (FAQ)</a></p>
</li>
</ul>
<h2 id="heading-the-framework-landscape-in-2024">The Framework Landscape in 2024</h2>
<p>Think of frameworks as tools in a technical toolbox. Understanding what each tool is designed to do—and what it isn't—ensures you use the right solution for the task at hand.</p>
<h3 id="heading-the-evolution-of-development-frameworks">The Evolution of Development Frameworks</h3>
<p>The framework landscape has transformed dramatically over the past decade. What started as simple libraries for rendering web pages has evolved into sophisticated ecosystems that can:</p>
<ul>
<li><p>Handle complex state management.</p>
</li>
<li><p>Process real-time data streams.</p>
</li>
<li><p>Integrate AI capabilities.</p>
</li>
<li><p>Scale automatically based on demand.</p>
</li>
<li><p>Deploy across multiple platforms from a single codebase.</p>
</li>
</ul>
<h3 id="heading-why-framework-choice-matters">Why Framework Choice Matters</h3>
<p>Frameworks are puzzle pieces: each has a unique shape and function. When chosen wisely, they fit together seamlessly to create a cohesive application. But forcing incompatible pieces together can lead to inefficiencies and broken functionality.</p>
<p>Here's why your choice matters:</p>
<h4 id="heading-technical-impact">Technical impact</h4>
<ul>
<li><p><strong>Performance</strong>: Different frameworks have different performance characteristics. Instagram chose React for its virtual DOM, which handles frequent updates efficiently.</p>
</li>
<li><p><strong>Scalability</strong>: Uber's back end uses Node.js because it excels at handling numerous concurrent connections.</p>
</li>
<li><p><strong>Maintenance</strong>: Shopify standardized on React Native to maintain a single codebase for mobile applications.</p>
</li>
</ul>
<h4 id="heading-business-impact">Business impact</h4>
<ul>
<li><p><strong>Development speed</strong>: The right framework can accelerate development by 2-3x.</p>
</li>
<li><p><strong>Team productivity</strong>: Familiar frameworks reduce onboarding time from months to weeks.</p>
</li>
<li><p><strong>Cost efficiency</strong>: Proper framework selection can significantly reduce hosting and maintenance costs.</p>
</li>
</ul>
<h4 id="heading-common-pitfalls">Common pitfalls</h4>
<ul>
<li><p><strong>Over-engineering</strong>: Using Next.js when a simple HTML page would suffice</p>
</li>
<li><p><strong>Under-engineering</strong>: Using vanilla JavaScript for a complex, state-heavy application</p>
</li>
<li><p><strong>Misaligned tools</strong>: Using Electron (a desktop app framework) to build a simple website</p>
</li>
<li><p><strong>Trend-chasing</strong>: Adopting the newest framework without considering maintenance implications</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731967899960/8c8b60fb-4370-4bb1-91fd-5b8b18db22e9.png" alt="A diagram of frameworks and their categorizations" width="600" height="400" loading="lazy"></p>
<p>Let’s dive deeper into the various categories of development frameworks and how they can help you build better applications.</p>
<p><strong>Note</strong>: I give framework examples throughout this article, but these are not exhaustive lists and new frameworks are created <code>daily|weekly|monthly</code>.</p>
<h2 id="heading-application-frameworks">Application Frameworks</h2>
<p>These are your Swiss Army knives of development—comprehensive toolkits that handle the entire application lifecycle. While each framework has its specialties, they typically provide:</p>
<ul>
<li><p>Database integration and ORM support.</p>
</li>
<li><p>Authentication and authorization.</p>
</li>
<li><p>API routing and middleware.</p>
</li>
<li><p>Template engines or component systems.</p>
</li>
<li><p>Asset management.</p>
</li>
<li><p>Security features.</p>
</li>
<li><p>Development tools and debugging support.</p>
</li>
</ul>
<p><strong>What is an application?</strong> An application is the combination of individual components working together, including a user interface and backend services, to perform specific functions or a set of functions for users. It’s designed to be fully deployable and operate in production environments.</p>
<p>You'll encounter them in three main flavors:</p>
<h3 id="heading-full-stack-web-application-frameworks">Full-Stack Web Application Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://www.djangoproject.com/"><strong>Django</strong></a> <strong>and</strong> <a target="_blank" href="https://rubyonrails.org/"><strong>Rails</strong></a>: Perfect for data-heavy applications with complex business logic. They follow the "batteries included" philosophy, providing everything you need out of the box.</p>
</li>
<li><p><a target="_blank" href="https://nextjs.org/"><strong>Next.js</strong></a> <strong>and</strong> <a target="_blank" href="https://nuxtjs.org/"><strong>Nuxt.js</strong></a>: Modern full-stack frameworks optimized for React and Vue.js, respectively. They excel at building performant applications with capabilities like server-side rendering, static site generation, and API integration.</p>
</li>
<li><p><a target="_blank" href="https://spring.io/projects/spring-boot"><strong>Spring Boot</strong></a>: Enterprise-grade framework favored for large-scale Java applications, particularly in financial and banking sectors.</p>
</li>
</ul>
<h3 id="heading-mobile-application-frameworks">Mobile Application Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://flutter.dev/"><strong>Flutter</strong></a>: Google's toolkit for building natively compiled apps for mobile, web, and desktop from a single codebase. Known for smooth animations and native performance.</p>
</li>
<li><p><a target="_blank" href="https://reactnative.dev/"><strong>React Native</strong></a>: Ideal when you want to leverage your team's React knowledge for mobile development. Great for apps that need to feel native while maintaining code sharing between platforms.</p>
</li>
<li><p><a target="_blank" href="https://developer.apple.com/xcode/swiftui/"><strong>SwiftUI</strong></a> <strong>and</strong> <a target="_blank" href="https://developer.android.com/jetpack/compose"><strong>Jetpack Compose</strong></a>: Native frameworks for iOS and Android, respectively. Ideal when platform-specific features and optimal performance are crucial.</p>
</li>
</ul>
<h3 id="heading-desktop-application-frameworks">Desktop Application Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://www.electronjs.org/"><strong>Electron</strong></a>: Powers apps like VS Code and Slack. Ideal for leveraging existing web development knowledge without having to learn OS-specific languages to build cross-platform desktop applications.</p>
</li>
<li><p><a target="_blank" href="https://tauri.app/"><strong>Tauri</strong></a>: A modern alternative to Electron with smaller bundle sizes and better performance. Uses native system webviews to run apps more efficiently, with less memory and faster startup times. Developers can use their existing web development skills without learning new programming languages for each OS.</p>
</li>
<li><p><a target="_blank" href="https://wiki.python.org/moin/PyQt"><strong>PyQt</strong></a>: A good option for building GUI applications in Python, especially for data science projects. It has a rich set of libraries and widgets, suitable for both small tools and complex apps.</p>
</li>
</ul>
<h3 id="heading-gaming-frameworks">Gaming Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://unity.com/"><strong>Unity</strong></a>: A popular framework used for creating 2D and 3D games. It supports multiple platforms, making it a versatile choice for game developers. Unity is known for its user-friendly interface and extensive asset store.</p>
</li>
<li><p><a target="_blank" href="https://www.unrealengine.com/"><strong>Unreal Engine</strong></a>: Known for its high-quality graphics, Unreal Engine is a powerful framework used for both AAA games and indie projects. It provides advanced visual tools and real-time rendering capabilities.</p>
</li>
<li><p><a target="_blank" href="https://godotengine.org/"><strong>Godot</strong></a>: An open-source game engine that's lightweight and flexible. Godot is often used for smaller or indie game projects and features an intuitive scene system that makes development straightforward.</p>
</li>
</ul>
<h2 id="heading-ai-frameworks">AI Frameworks</h2>
<p>Here's a crucial point many miss: AI frameworks like TensorFlow or LangChain are powerful, but they're not standalone solutions. These frameworks require integration with other tools and frameworks for data handling, user interface, and deployment to create a complete, production-ready application. These are just another piece of the puzzle.</p>
<p><strong>The exception?</strong> Data scientists can use these tools directly in Jupyter notebooks for research and prototyping. But for production applications, you'll need more.</p>
<p>Let's look at the major players and their sweet spots:</p>
<h3 id="heading-ai-model-development-frameworks">AI Model Development Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://www.tensorflow.org/"><strong>TensorFlow</strong></a>: Google's powerhouse for deep learning, TensorFlow is perfect for applications involving computer vision, neural networks, and production-grade ML. Pinterest uses it for image recognition and recommendations, highlighting its strength in processing large amounts of image data efficiently.</p>
</li>
<li><p><a target="_blank" href="https://pytorch.org/"><strong>PyTorch</strong></a>: Developed by Facebook, PyTorch is a flexible framework ideal for research, natural language processing, and quick prototyping. Tesla has utilized PyTorch for various machine learning tasks, including research related to autonomous driving vision systems, demonstrating its versatility in cutting-edge applications.</p>
</li>
<li><p><a target="_blank" href="https://github.com/google/jax"><strong>JAX</strong></a>: A high-performance numerical computing framework by Google, JAX is well-suited for scientific computing and large-scale transformers. DeepMind has used JAX for advanced AI research, including projects like AlphaFold for protein structure prediction, showcasing its effectiveness in large-scale computational problems.</p>
</li>
</ul>
<h3 id="heading-ai-model-deployment-and-serving-frameworks">AI Model Deployment and Serving Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://github.com/tensorflow/serving"><strong>TensorFlow Serving</strong></a>: A deployment tool for TensorFlow models, perfect for serving high-performance ML models in production environments. For example, it has been used to serve image classification models for e-commerce platforms, ensuring rapid and scalable response times.</p>
</li>
<li><p><a target="_blank" href="https://pytorch.org/serve/"><strong>TorchServe</strong></a>: A robust tool for deploying PyTorch models, perfect for scalable PyTorch model serving. It has been used for deploying chatbot models for real-time customer support, providing flexibility and efficiency in managing conversational AI.</p>
</li>
<li><p><a target="_blank" href="https://developer.nvidia.com/triton-inference-server"><strong>NVIDIA Triton Inference Server</strong></a>: A multi-framework model serving tool, NVIDIA Triton Inference Server is capable of handling models from TensorFlow, PyTorch, ONNX, and more. It is ideal for managing inference requests for multi-modal AI applications, making it highly suitable for complex AI deployments.</p>
</li>
</ul>
<h3 id="heading-llm-integration-frameworks">LLM Integration Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://langchain.io/"><strong>LangChain</strong></a>: The Swiss Army knife for LLM applications. Ideal for building chatbots and document Q&amp;A systems. It has been employed to create customer service bots capable of accessing company knowledge bases, demonstrating its usefulness in enhancing customer interactions.</p>
</li>
<li><p><a target="_blank" href="https://www.llamaindex.ai/"><strong>LlamaIndex</strong></a>: Specializing in data connection, LlamaIndex is perfect for building search engines over private data. It has been used to create semantic search systems for internal documents, facilitating more effective data retrieval and organizational knowledge management.</p>
</li>
<li><p><a target="_blank" href="https://huggingface.co/docs/transformers/en/index"><strong>Hugging Face Transformers</strong></a>: A pre-trained model hub, Hugging Face Transformers allows for the quick deployment of state-of-the-art models. It has been used to add sentiment analysis to customer feedback systems, highlighting its capability in natural language understanding.</p>
</li>
</ul>
<h3 id="heading-ai-data-processing-frameworks">AI Data Processing Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://spark.apache.org/mllib/"><strong>Apache Spark (MLlib)</strong></a>: Ideal for large-scale data transformation and ML, used for processing millions of user interactions in recommendation systems. Its scalability and efficiency make it a popular choice for big data ML tasks.</p>
</li>
<li><p><a target="_blank" href="https://pandas.pydata.org/"><strong>Pandas</strong></a>: A widely-used data manipulation and analysis tool that is perfect for data cleaning, analysis, and feature engineering. It is often employed in preparing customer data for churn prediction models, owing to its intuitive data handling capabilities.</p>
</li>
<li><p><a target="_blank" href="https://www.pola.rs/"><strong>Polars</strong></a>: A high-performance data manipulation framework, used when Pandas is not fast enough for processing requirements. It has been applied in real-time financial data analysis, delivering faster data processing and efficiency.</p>
</li>
</ul>
<h3 id="heading-ai-automation-and-orchestration-frameworks">AI Automation and Orchestration Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://crewai.com/"><strong>CrewAI</strong></a>: Used to orchestrate multiple AI agents, making it perfect for complex workflows requiring multiple AI models. It has been used to create a content creation pipeline that plans, writes, and edits, showcasing its ability to automate creative processes.</p>
</li>
<li><p><a target="_blank" href="https://github.com/Torantulino/Auto-GPT"><strong>Auto-GPT</strong></a>: Develops autonomous AI agents, ideal for self-directed task completion. It has been utilized for automated research and data gathering, highlighting its potential for automating repetitive knowledge tasks.</p>
</li>
<li><p><a target="_blank" href="https://github.com/microsoft/semantic-kernel"><strong>Microsoft Semantic Kernel</strong></a>: An AI orchestration tool perfect for integrating AI into .NET applications. It has been used to add AI capabilities to existing enterprise applications, providing a seamless integration of AI functions into established workflows.</p>
</li>
</ul>
<h3 id="heading-ai-data-ingestion-and-document-processing-frameworks">AI Data Ingestion and Document Processing Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://nifi.apache.org/"><strong>Apache NiFi</strong></a>: A powerful tool for data flow automation, well-suited for real-time data ingestion and processing. It has been used to extract and transform log data before analysis, ensuring efficient data flow for various use cases.</p>
</li>
<li><p><a target="_blank" href="https://haystack.deepset.ai/"><strong>Haystack</strong></a>: Specialized in document processing for search and QA systems. It has been utilized to create pipelines for indexing documents and answering questions, making it ideal for building internal knowledge base searches.</p>
</li>
<li><p><a target="_blank" href="https://unstructured.io/"><strong>Unstructured</strong></a>: Designed for extracting data from a variety of formats, including PDFs, HTML, and images. It’s perfect for handling unstructured content in document processing workflows and has been used to extract relevant information from scanned documents for data analysis.</p>
</li>
<li><p><a target="_blank" href="https://airbyte.com/"><strong>Airbyte</strong></a>: An open-source data integration tool that is ideal for connecting and syncing data across multiple sources. It has been used to ingest data from third-party APIs into analytics systems, enabling effective data consolidation.</p>
</li>
</ul>
<h3 id="heading-interactive-ai-web-frameworks">Interactive AI Web Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://gradio.app/"><strong>Gradio</strong></a>: Simplifies the process of building web UIs for machine learning models, making it perfect for creating quick demos for ML models. It has been used to create interactive image classifiers for end users, providing an accessible interface for testing ML capabilities.</p>
</li>
<li><p><a target="_blank" href="https://streamlit.io/"><strong>Streamlit</strong></a>: A Python-based web app framework for ML and data science, ideal for turning data scripts into shareable web apps. It has been used to build user-friendly dashboards for exploring model predictions, enhancing the accessibility of ML models.</p>
</li>
</ul>
<h3 id="heading-mlops-and-ai-monitoring-frameworks">MLOps and AI Monitoring Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://mlflow.org/"><strong>MLflow</strong></a>: Used for experiment tracking and model lifecycle management, perfect for keeping track of experiments and model versions. It has been applied to manage multiple iterations of predictive models, supporting organized development workflows.</p>
</li>
<li><p><a target="_blank" href="https://www.kubeflow.org/"><strong>Kubeflow</strong></a>: A Kubernetes-native platform for MLOps, ideal for deploying, scaling, and managing machine learning models on Kubernetes. It has been used to run end-to-end ML workflows in production environments, ensuring scalability and consistency.</p>
</li>
<li><p><a target="_blank" href="https://prometheus.io/"><strong>Prometheus</strong></a> &amp; <a target="_blank" href="https://grafana.com/"><strong>Grafana</strong></a>: Monitoring and alerting tools for ML infrastructure, perfect for tracking model inference performance and system metrics. They have been used to monitor latency and resource usage of deployed ML services, ensuring optimal operational performance.</p>
</li>
</ul>
<h2 id="heading-web-frameworks">Web frameworks</h2>
<p>Web development has evolved into two distinct camps—think of them as the front-of-house and kitchen staff in a restaurant. Both essential, both specialized, but with very different responsibilities.</p>
<p><strong>Note</strong>: We already discussed full-stack web application frameworks above, which marry these two together.</p>
<h3 id="heading-frontend-frameworks">Frontend Frameworks</h3>
<p>Frontend frameworks handle what users see and interact with, managing everything from data display to user interactions, user input, and how the overall user experience is structured. These frameworks ensure that the interface is visually appealing, intuitive, and responsive to user actions.</p>
<p>They play a critical role in how smoothly data is presented, processed, and updated in real time, providing dynamic elements like animations, form validation, and client-side routing to enhance usability.</p>
<p>By using frontend frameworks, developers can create highly interactive and cohesive user experiences that feel natural and engaging.</p>
<ul>
<li><p><a target="_blank" href="https://reactjs.org/"><strong>React</strong></a>: Ideal for large-scale applications with complex state management. It features a virtual DOM for optimal performance, making it suitable for highly interactive user interfaces.</p>
</li>
<li><p><a target="_blank" href="https://vuejs.org/"><strong>Vue.js</strong></a>: Perfect for both small projects and enterprise applications. It has a gentle learning curve combined with powerful scalability, making it an approachable yet robust frontend solution.</p>
</li>
<li><p><a target="_blank" href="https://svelte.dev/"><strong>Svelte</strong></a>: Ideal for when you have performance-critical applications and want smaller bundles. It compiles away framework code for lighter applications, providing better performance and a smaller footprint.</p>
</li>
</ul>
<h3 id="heading-backend-frameworks">Backend Frameworks</h3>
<p>Backend frameworks manage server-side logic, data processing, and system integration, handling everything from receiving and processing client requests to interacting with databases and external APIs. These frameworks ensure that the server processes are efficient, scalable, and secure, supporting high concurrency and maintaining consistent data flows.</p>
<p>They provide the essential tools for developers to build, maintain, and optimize the server-side of applications, including tasks such as handling authentication, managing business logic, and ensuring data consistency.</p>
<p>A well-chosen backend framework allows developers to focus more on creating features rather than dealing with low-level server management.</p>
<ul>
<li><p><a target="_blank" href="https://expressjs.com/"><strong>Express.js</strong></a>: Perfect for APIs and microservices, offering minimal structure with maximum flexibility. It is highly popular in Node.js environments for building efficient server-side logic.</p>
</li>
<li><p><a target="_blank" href="https://fastapi.tiangolo.com/"><strong>FastAPI</strong></a>: Designed for high-performance APIs, with automatic API documentation and type checking. It is commonly used for fast and secure backend implementations in Python.</p>
</li>
<li><p><a target="_blank" href="https://nestjs.com/"><strong>NestJS</strong></a>: For large-scale Node.js applications, featuring an Angular-inspired architecture that enhances scalability. It provides a well-structured framework for enterprise-level backends.</p>
</li>
</ul>
<h2 id="heading-cssui-frameworks">CSS/UI Frameworks</h2>
<p>Modern CSS frameworks have evolved beyond simple styling to become complete design systems. Gone are the days when CSS frameworks just provided basic grid systems and button styles.</p>
<p>Today's frameworks are sophisticated tools that enable consistent design at scale. They offer features such as responsive layouts, dark mode support, accessibility enhancements, and interactive components.</p>
<p>They've become essential for maintaining design consistency across large applications and teams, while significantly reducing development time and technical debt. Some frameworks even include built-in performance optimization, design tokens for brand customization, and tools for managing design systems across multiple platforms.</p>
<p>They fall into two main categories:</p>
<h3 id="heading-utility-first-frameworks">Utility-first Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://tailwindcss.com/"><strong>Tailwind CSS</strong></a>: Custom designs with consistent systems. It features rapid prototyping capabilities, highly customizable design tokens, and small production bundles through PurgeCSS.</p>
</li>
<li><p><a target="_blank" href="https://unocss.dev/"><strong>UnoCSS</strong></a>: A customizable, efficient, utility-first CSS solution. It provides on-demand CSS for optimal performance and minimal bundle size, making it a modern tool for design system management.</p>
</li>
</ul>
<h3 id="heading-component-based-frameworks">Component-based Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://getbootstrap.com/"><strong>Bootstrap</strong></a>: Rapid prototyping and traditional web applications. It offers an extensive library of pre-built components, a responsive grid system, and a rich ecosystem of themes and plugins.</p>
</li>
<li><p><a target="_blank" href="https://mui.com/"><strong>Material UI</strong></a>: For applications following Material Design guidelines. It includes a comprehensive component library, a theming system, and accessibility compliance features.</p>
</li>
</ul>
<h2 id="heading-testing-and-infrastructure">Testing and Infrastructure</h2>
<p>These frameworks form the backbone of reliable, scalable applications. While they might not get as much attention as flashy frontend frameworks or AI tools, they're the critical infrastructure that keeps modern applications running smoothly at scale.</p>
<p>Testing frameworks ensure code quality and prevent regressions, while containerization and orchestration frameworks handle the increasingly complex world of cloud deployment and scaling.</p>
<p>In an era where a single code change can affect millions of users instantly, or where an application might need to scale from hundreds to millions of requests in minutes, these frameworks aren't just nice-to-have—they're essential for survival. Major tech companies like Netflix, Amazon, and Google rely on these tools to maintain their rapid development pace while ensuring reliability and performance at massive scale.</p>
<h3 id="heading-testing-frameworks">Testing Frameworks</h3>
<ul>
<li><p><a target="_blank" href="https://jestjs.io/"><strong>Jest</strong></a>: Features snapshot testing, code coverage, and mocking capabilities, making it a popular choice for ensuring the quality of JavaScript codebases.</p>
</li>
<li><p><a target="_blank" href="https://www.cypress.io/"><strong>Cypress</strong></a>: Provides real browser testing and time-travel debugging, ideal for end-to-end testing of web applications.</p>
</li>
<li><p><a target="_blank" href="https://docs.pytest.org/en/stable/"><strong>PyTest</strong></a>: Known for its simple syntax, powerful extensions, and easy fixture management, making it a go-to framework for testing Python applications.</p>
</li>
</ul>
<h3 id="heading-containerization-and-orchestration">Containerization and Orchestration</h3>
<ul>
<li><p><a target="_blank" href="https://www.docker.com/"><strong>Docker</strong></a>: Used for application containerization, providing consistent development and deployment environments with isolated dependencies and efficient resource usage.</p>
</li>
<li><p><a target="_blank" href="https://kubernetes.io/"><strong>Kubernetes</strong></a>: Orchestration of large-scale distributed applications. It provides automated scaling, self-healing deployments, and rolling updates, ensuring that containerized applications can grow as needed.</p>
</li>
</ul>
<h2 id="heading-making-the-right-choice">Making the Right Choice</h2>
<p>Selecting the right framework can determine the success of your entire project. Consider these critical points to guide your decision-making process:</p>
<h3 id="heading-1-application-type-and-scale">1. Application Type and Scale</h3>
<ul>
<li><p>Small site? Consider React or Vue.js.</p>
</li>
<li><p>Large application? Next.js or Django might be better.</p>
</li>
<li><p>Need SEO? Look for SSR capabilities.</p>
</li>
</ul>
<h3 id="heading-2-team-capabilities">2. Team Capabilities</h3>
<ul>
<li><p>Strong JavaScript? Consider Node.js ecosystem.</p>
</li>
<li><p>Python experts? Django or FastAPI might be better.</p>
</li>
<li><p>Need quick ramp-up? Combine key frameworks like Vue.js and Bootstrap.</p>
</li>
</ul>
<h3 id="heading-3-technical-requirements">3. Technical Requirements</h3>
<ul>
<li><p>High-performance computing? Consider Rust frameworks.</p>
</li>
<li><p>Real-time updates? Look at WebSocket support.</p>
</li>
<li><p>AI requirements? Integration with platforms like Hugging Face and frameworks like LangChain might be essential.</p>
</li>
</ul>
<h3 id="heading-4-scaling-strategy">4. Scaling Strategy</h3>
<ul>
<li><p>Vertical scaling? Simpler frameworks might suffice.</p>
</li>
<li><p>Horizontal scaling? You need frameworks with microservices support.</p>
</li>
<li><p>Global distribution? Consider edge computing capabilities.</p>
</li>
</ul>
<h3 id="heading-5-long-term-maintenance">5. Long-term Maintenance</h3>
<ul>
<li><p>Community size and activity</p>
</li>
<li><p>Available talent pool</p>
</li>
<li><p>Corporate backing and stability</p>
</li>
<li><p>Documentation quality</p>
</li>
<li><p>Upgrade path complexity</p>
</li>
</ul>
<h2 id="heading-the-bottom-line">The Bottom Line</h2>
<p>Framework selection isn't just a technical decision—it's a strategic one that affects your project's success, team productivity, and maintenance costs. So take the time to understand your options.</p>
<p>Now you should have all of the puzzle pieces, but it's up to you to put them together thoughtfully to create the perfect technology stack that meets both your current and future needs.</p>
<h2 id="heading-additional-resources">Additional Resources</h2>
<p>If you'd like to learn how <a target="_blank" href="https://mdb.link/register-frameworks">MongoDB</a> integrates seamlessly with many of the frameworks mentioned in this guide, check out the resources below. You'll find that it offers a flexible and scalable database solution that adapts to different use cases.</p>
<ul>
<li><p><a target="_blank" href="https://mdb.link/frameworks-nextjs">How to Integrate MongoDB Into Your Next.js App</a></p>
</li>
<li><p><a target="_blank" href="https://mdb.link/frameworks-farm">Introducing FARM Stack - FastAPI, React, and MongoDB</a></p>
</li>
<li><p><a target="_blank" href="https://mdb.link/frameworks-mern">How to Use MERN Stack: A Complete Guide</a></p>
</li>
<li><p><a target="_blank" href="https://mdb.link/frameworks-langchainjs">Build a JavaScript AI Agent With LangGraph.js and MongoDB</a></p>
</li>
<li><p><a target="_blank" href="https://mdb.link/frameworks-langchain">RAG with Atlas Vector Search, LangChain, and OpenAI</a></p>
</li>
</ul>
<h2 id="heading-frequently-asked-questions-faq"><strong>Frequently Asked Questions (FAQ)</strong></h2>
<h3 id="heading-what-is-a-development-framework">What is a development framework?</h3>
<p>A development framework is a set of tools, libraries, and conventions that provide a foundation for building applications efficiently. Frameworks handle common tasks so developers can focus on building unique features.</p>
<h3 id="heading-how-do-ai-and-development-frameworks-work-together">How do AI and development frameworks work together?</h3>
<p>AI frameworks can be combined with traditional development frameworks to create intelligent, data-driven applications. For instance, a backend framework like FastAPI can handle incoming requests, while an AI framework like LangChain processes natural language data, providing users with enhanced functionality like chatbots or recommendation systems.</p>
<h3 id="heading-why-is-choosing-the-right-framework-important">Why is choosing the right framework important?</h3>
<p>Choosing the right framework can impact your project's performance, scalability, and maintenance. It ensures that your application meets user expectations, is easy to manage, and can grow as needed.</p>
<h3 id="heading-how-do-i-decide-which-framework-to-use-for-my-project">How do I decide which framework to use for my project?</h3>
<p>Consider factors like application type, team expertise, performance needs, scalability, and long-term maintenance. Each of these can guide you in selecting a framework that matches your specific requirements.</p>
<h3 id="heading-can-i-use-multiple-frameworks-in-one-project">Can I use multiple frameworks in one project?</h3>
<p>Yes, combining multiple frameworks can be very effective. You might use one framework for the front end, another for backend services, and a third for AI integrations, ensuring that each part of your application is handled by the best-suited tool.</p>
<h3 id="heading-how-does-mongodb-fit-into-development-frameworks">How does MongoDB fit into development frameworks?</h3>
<p>MongoDB integrates with many frameworks, acting as the data layer for your applications. It provides a flexible, scalable solution that supports full-stack, backend, and AI frameworks to store and retrieve data efficiently.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ JavaScript Frameworks vs Laravel – Which Should You Choose for Web Development? ]]>
                </title>
                <description>
                    <![CDATA[ For a long time, developers in the JavaScript ecosystem have tried to launch Laravel-like frameworks for JavaScript. We've seen Blitz for NextJS, Adonis for NodeJS, RedwoodJS, and more. All these frameworks tried to build a Laravel for JavaScript. Bu... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/javascript-frameworks-vs-laravel/</link>
                <guid isPermaLink="false">66d45d5a33b83c4378a517b0</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Afan Khan ]]>
                </dc:creator>
                <pubDate>Mon, 17 Jun 2024 14:28:11 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/Group-3148.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>For a long time, developers in the JavaScript ecosystem have tried to launch Laravel-like frameworks for JavaScript.</p>
<p>We've seen Blitz for NextJS, Adonis for NodeJS, RedwoodJS, and more. All these frameworks tried to build a Laravel for JavaScript.</p>
<p>But none of them were really successful. Why? We'll figure it out in this article. It's worth going over because beginners learning JavaScript struggle to find an all-in-one solution.</p>
<p>This means it can be tough to choose a framework (or library) in JavaScript when you have so many choices – like React, Vue, Angular, Svelte, NextJS, Meteor, and more.</p>
<p>Meanwhile, PHP offers one simple solution: Laravel. It's a one-stop shop with many frameworks and libraries combined into one. But is it the right option for you?</p>
<p>In this article, I'll dive deeper into why the JavaScript ecosystem doesn't have a Laravel-like framework and whether you should switch to PHP for a one-stop solution like Laravel.</p>
<p>I will discuss the advantages and disadvantages of using JavaScript frameworks compared to a one-stop solution like Laravel and end it with a comparison table to help you decide.</p>
<h2 id="heading-what-well-cover-in-this-article">What we'll cover in this article:</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-why-javascript-vs-laravel">Why JavaScript vs Laravel</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-why-javascript-lacks-an-all-in-one-solution">Why JavaScript lacks an all-in-one solution</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-benefits-of-javascript-frameworks-and-libraries">Benefits of JavaScript frameworks and libraries</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-benefits-of-laravel">Benefits of Laravel</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-differences-between-laravel-and-js-tools">Differences between Laravel and JS tools</a></p>
</li>
</ol>
<h2 id="heading-why-javascript-vs-laravel">Why JavaScript vs Laravel</h2>
<p>When beginners decide to learn Web Development, they often choose between JavaScript/TypeScript and PHP. Other solutions require more expertise, so most beginners gravitate towards these two languages.</p>
<p>Many JavaScript beginners eventually find its vast ecosystem overwhelming, whereas PHP learners often feel constrained by the limited frameworks and lack of advanced capabilities.</p>
<p>To deal with that confusion, I am comparing the tools available for JavaScript and PHP, not the languages directly. Since PHP has an all-in-one solution most developers use, I'll use Laravel for the comparison.</p>
<p>JavaScript lacks a single all-in-one solution or a specific representative framework. Therefore, I'll refer to tools like React, Vue, Angular, and so on as "JavaScript Frameworks."</p>
<p>Let's begin by understanding why the JavaScript ecosystem lacks a Laravel-like framework.</p>
<h2 id="heading-why-javascript-lacks-an-all-in-one-solution">Why JavaScript Lacks an All-in-One Solution</h2>
<p>I'll begin by acknowledging that JavaScript developers have tried in the past to make a Laravel for JavaScript.</p>
<p>Start with RedwoodJS. It's an open-source full-stack JavaScript framework started by Tom Preston-Werner, the co-founder and former CEO of GitHub. It helps developers build their applications and ship faster.</p>
<p>Redwood has many innovative solutions packed into one framework. Sounds familiar? That's precisely like Laravel. Do you see anyone shipping using Redwood? Most likely not.</p>
<p>The next option is Blitz. It makes the same promise as Redwood: a replacement for NextJS. Blitz is an all-in-one solution with custom built-in solutions for authentication, database, and so on.</p>
<p>But Blitz doesn't allow developers to choose what they want to use, like Laravel. It has custom solutions crafted by the core team. Developers cannot replace any solution piece with some other recommended solution.</p>
<p>Customization is a point worth noting in the JavaScript ecosystem, and I'll explain why as we uncover more frameworks. But Blitz didn't succeed either.</p>
<p>Then, there's AdonisJS. But, I think you get the point. Each all-in-one solution in JavaScript has tried to implement their version of Laravel – and none of them really took hold.</p>
<p>Blitz, Adonis, and Redwood followed a theme: a full-stack framework of ready-made non-customizable solutions for JavaScript developers to build applications.</p>
<p>These frameworks didn't gain popularity because they didn't meet the needs of the developers they aimed to serve.</p>
<p>The JavaScript ecosystem is unique, offering many solutions for the same problem. There's a reason for this diversity, and why those frameworks didn't succeed.</p>
<p>Let's discuss the reasons and benefits of the current popular JavaScript tools, as they directly impact the choice between JavaScript frameworks and Laravel. As I outline each benefit, consider whether it aligns with your needs.</p>
<h2 id="heading-benefits-of-javascript-frameworks-and-libraries">Benefits of JavaScript Frameworks and Libraries</h2>
<p>JavaScript frameworks and libraries are collections of pre-written resources, techniques, and functions created by developers to save time and effort.</p>
<p>These frameworks began emerging in the 2000s, with notable ones like React, Svelte, Angular, NextJS, and Vue standing out over time.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/image-80.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://raygun.com/blog/popular-javascript-frameworks/"><em>Raygun</em></a></p>
<p>However, having more options doesn't necessarily mean greater effectiveness. Below, we’ll explore the benefits of using JavaScript frameworks and why all-in-one solutions haven't succeeded in the JavaScript ecosystem.</p>
<h3 id="heading-versatility">Versatility</h3>
<p>It's easier to switch or choose one solution over the other in the JavaScript ecosystem. For example, to implement authentication, we have Clerk, Auth0, AuthJS, NextAuth, Supabase, and more.</p>
<p>The JavaScript ecosystem always had multiple options for a specific solution and startups dedicated to providing bespoke solutions. If you didn't like Clerk, you could use NextAuth for more customization.</p>
<p>JavaScript frameworks are highly versatile. When there are ten solutions for one problem, developers can easily switch and see what works for them.</p>
<p>Blitz and other frameworks couldn't succeed for this reason. If a developer disliked Blitz's approach to authentication, they would just switch to another solution.</p>
<h3 id="heading-npm">NPM</h3>
<p>Unlike JavaScript, other languages don't have an ecosystem around building tools for others, like libraries or packages. It's not as easy in those languages.</p>
<p>The JavaScript ecosystem has an entire registry filled with packages and libraries for the smallest solutions, like emails. JavaScript has many packages, frameworks, and libraries for each solution.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/image-81.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://kinsta.com/knowledgebase/what-is-npm/"><em>Kinsta</em></a></p>
<p>Ironically, even the NPM registry has competitors. There are multiple other registries with unique packages and features. JavaScript follows the versatility rule everywhere, but does that indicate reliability? Maybe not.</p>
<h3 id="heading-startups">Startups</h3>
<p>Each solution for a specific problem is likely a startup funded by VC firms and Angel Investors.</p>
<p>JavaScript-based startups have the capital and the resources to conduct in-depth research and hire the best talent to build bespoke solutions for a targeted problem.</p>
<p>With unlimited resources allocated to a specific topic or problem, the solutions are specific and cater to different needs to their developers.</p>
<p>In return, JavaScript developers pay these startups for those solutions and startups are incentivised to create better solutions for the ecosystem.</p>
<h3 id="heading-the-common-dev">The Common Dev</h3>
<p>Any developer in the JavaScript ecosystem can identify a problem during their experience using a specific technology, build a solution, and offer it as a product.</p>
<p>JavaScript developers have the liberty to build and sell their solutions because startups push the idea of paying for bespoke solutions and developers have no problem doing that.</p>
<p>Take <a target="_blank" href="https://x.com/marc_louvion">Marc Lou</a> as an example. He built <a target="_blank" href="https://shipfa.st/">ShipFast</a> and other products that churn over $100,000 per month. He is an example of the possibilities in the field.</p>
<p>But perhaps these benefits and reasons seem intangible to you. Don’t worry—the web development domain offers more than one alternative. Let’s explore Laravel.</p>
<h2 id="heading-laravel">Laravel</h2>
<p>Laravel is a framework for the PHP programming language. Taylor Otwell introduced Laravel in 2011.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/image-45.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source: Cloudways</em></p>
<p>Laravel offers many solutions packed into one tool, and can be a one-stop solution for everything. It offers authentication, debugging, serverless deployment, user-friendly form systems, starter kits, and so on.</p>
<p>The solutions provided by Laravel are many, but without the core language, they don't mean anything. Laravel is all about PHP.</p>
<p>PHP is a general-purpose scripting language. Rasmus Lardof introduced it to developers in the 1990s. Since then, the language has evolved with significant updates in 2004, 2015, and 2020.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/image-46.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source: Gecko Dynamics</em></p>
<p>Before JavaScript frameworks had taken off, developers used PHP with JavaScript.</p>
<p>Laravel is a back-end framework and PHP focuses on the server-side. JavaScript without a framework is a client-side language at its core.</p>
<p>Developers traditionally used JavaScript on the client-side and PHP on the server-side to create full-fledged applications.</p>
<p>However, the tech stack landscape shifted when Laravel gained popularity and frameworks like React began to dominate the JavaScript ecosystem.</p>
<p>Many developers worldwide, especially from countries like India, are doubling down on PHP because of its robust and reliable nature.</p>
<p>Government websites and large infrastructures use Laravel (PHP) because it supports a variety of solutions in one place. Many developers don't want to combine and switch technologies.</p>
<p>Companies and individuals using PHP or Laravel want to ship quickly, make changes, and avoid learning a new library or technology at every step of the way like JavaScript.</p>
<p>PHP only has JavaScript as its direct rival that challenges its existence. However, JavaScript isn't the best for many situations. Let's see how Laravel performs better.</p>
<h2 id="heading-benefits-of-laravel">Benefits of Laravel</h2>
<h3 id="heading-one-stop-solution">One-Stop Solution</h3>
<p>Laravel is an all-in-one framework. It contains everything a developer would reasonably require to build compact, reliable, and robust solutions.</p>
<p>You don't need to spend time searching for various libraries and frameworks that may or may not integrate well with your foundational technology—it's all built-in for you.</p>
<p>If speed of deployment is your priority, Laravel is the ideal choice.</p>
<p>Moreover, for PHP developers using Laravel, there's less need to learn new libraries, syntax, and more because everything is integrated seamlessly.</p>
<h3 id="heading-less-wasted-time">Less Wasted Time</h3>
<p>The PHP ecosystem has fewer solutions for specific problems. It's difficult to identify a specific solution for a specific problem.</p>
<p>Developers rather choose an all-in-one solution than invest time in finding bespoke solutions for specific problems.</p>
<p>That's where the PHP ecosystem shines because developers don't spend a lot of time trying out different options. They already have everything in one place.</p>
<p>If there's a new project, their go-to choice is Laravel. In the JavaScript land, if a developer isn't using an existing solution or tech stack, they are likely finding a new one or creating one.</p>
<h3 id="heading-stable-and-robust">Stable and Robust</h3>
<p>Web Applications created using PHP are robust because the framework is battle-tested. You can create anything using it.</p>
<p>You could sabotage the entire application if you mess up with one choice of library or framework in a JavaScript project. But it's not the same with Laravel.</p>
<p>Since Laravel has fewer solutions, the chances of sabotaging are reduced to the bare minimum.</p>
<h3 id="heading-no-catching-up">No Catching Up</h3>
<p>With Laravel, you don't need to catch up with new technologies and frameworks frequently. You can learn one framework, library, or skill and consider it useful for a long time.</p>
<p>It's the opposite in JavaScript. Unlike JS, Laravel has more stable and less frequent updates.</p>
<p>The PHP ecosystem receives fewer updates so developers can reliably use the existing features without worrying about another framework or library providing a better solution or another version.</p>
<p>A new framework or library doesn't pop up each week. You don't need to follow up on versions frequently.</p>
<h3 id="heading-a-massive-community">A Massive Community</h3>
<p>Laravel was first launched a decade ago. It has gained popularity over time and invited many developers to create communities and share ideas.</p>
<p>Every PHP developer uses Laravel. If you ever need any help, you always have developers helping you.</p>
<h3 id="heading-free-solutions">Free Solutions</h3>
<p>Most PHP frameworks and libraries are open-source and free to access. Startups are rare in the PHP ecosystem.</p>
<p>If a developer is offering any bespoke solutions, most are public, especially free.</p>
<p>Any PHP developer can refer to those open-source free solutions, contribute to them, and extend those solutions further.</p>
<h2 id="heading-differences-between-laravel-and-js-tools">Differences Between Laravel and JS Tools</h2>
<p>You can create any type of application using both of these technologies. But the experience won't be exactly the same, of course. Here are some of the differences:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Features</td><td>JavaScript Frameworks</td><td>Laravel</td></tr>
</thead>
<tbody>
<tr>
<td>Beginner Friendly</td><td>They often use TypeScript, which is beginner-friendly and beneficial for developers switching from C, C#, Java, and C++</td><td>Laravel is easier to adopt if you have a grasp of PHP or other JavaScript frameworks.</td></tr>
<tr>
<td>Flexibility</td><td>High flexibility with the ability to choose different tools and libraries.</td><td>Less flexibility but provides a cohesive, opinionated structure.</td></tr>
<tr>
<td>Salary</td><td>Developers using JavaScript frameworks have higher salaries.</td><td>Laravel developers get a generally lower salary than JavaScript/TypeScript developers.</td></tr>
<tr>
<td>Availability of tools</td><td>JavaScript frameworks are widely available and ready-to-use. You can download them from the NPM registry and start immediately.</td><td>Laravel offers solutions for a wide range of problems, but if you encounter issues with their built-in solutions, you have fewer alternatives.</td></tr>
<tr>
<td>Security</td><td>Depends on the back-end setup of the respective framework, but there are options to choose from if the security measures lack.</td><td>It has built-in security features like CSRF and encryption.</td></tr>
<tr>
<td>Documentation</td><td>Depends on the framework. React, NextJS, and a few other frameworks have the most detailed documentations with code snippets and explanations.</td><td>Laravel has a structured and organised documentation with code snippets and explanations.</td></tr>
<tr>
<td>Testing &amp; Debugging</td><td>JavaScript frameworks have multiple testing libraries, like Jest.</td><td>Laravel has built-in tools, like PHPUnit intergration for testing.</td></tr>
<tr>
<td>Learning Curve</td><td>JavaScript frameworks have a higher learning curve due to frequent and significant updates, as well as the regular release of new frameworks.</td><td>Laravel has a gentle learning curve because its built-in solutions are easy to adopt, even for those familiar with JavaScript frameworks.</td></tr>
<tr>
<td>Scalability</td><td>JavaScript frameworks are highly scalable, allowing you to swap libraries as needed to maximize performance.</td><td>Laravel has limited options to modify and swap solutions. Hence, it is less scalable, but reliable.</td></tr>
<tr>
<td>Deployment &amp; Hosting</td><td>JavaScript frameworks can be deployed with any VPS, or using Vercel with a few clicks. However, it requires NodeJS on the server.</td><td>Laravel projects can be hosted on any server supporting PHP.</td></tr>
<tr>
<td>Customization</td><td>JavaScript frameworks allow for easy swapping and customization, enabling you to tailor libraries or frameworks to suit your needs.</td><td>Laravel solutions are limited and cannot be modified.</td></tr>
<tr>
<td>Performance</td><td>JavaScript frameworks have high-performance for dynamic, interactive Uls.</td><td>Laravel has high-performance for back-end processes and server-side rendering.</td></tr>
<tr>
<td>Future</td><td>JavaScript frameworks continue to grow, with more startups being founded and developers launching their own solutions.</td><td>Laravel continuously evolves, releasing new sub-frameworks and solutions to address problems in the most effective way possible.</td></tr>
</tbody>
</table>
</div><p>And that's it! I hope you enjoyed the article and learned something new. If you want, you can also follow me on <a target="_blank" href="https://x.com/whyafan">Twitter</a> (X) or <a target="_blank" href="https://www.linkedin.com/in/khanafan/">LinkedIn</a>. Also, I've built a <a target="_blank" href="https://store.afankhan.com/l/codenexus">Notion Dashboard</a> for Software Engineers to ace their coding interviews.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Framework? Software Frameworks Definition ]]>
                </title>
                <description>
                    <![CDATA[ When you're learning to code, you'll frequently hear the term "framework". And it can be difficult for new developers to grasp. You'll commonly come across frameworks in roadmap resources, when speaking with other developers, when learning about a ne... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-framework-software-frameworks-definition/</link>
                <guid isPermaLink="false">66d4600455db48792eed3f69</guid>
                
                    <category>
                        <![CDATA[ beginners guide ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joel Olawanle ]]>
                </dc:creator>
                <pubDate>Tue, 06 Sep 2022 17:52:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/09/cover-template--5-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When you're learning to code, you'll frequently hear the term "framework". And it can be difficult for new developers to grasp.</p>
<p>You'll commonly come across frameworks in roadmap resources, when speaking with other developers, when learning about a new coding tool, and many other places.</p>
<p>In this article, you will learn what a framework is in software engineering, why you need frameworks, the different types of frameworks that exist (and examples of them), and how you can get started learning a framework.</p>
<h2 id="heading-what-is-a-software-framework">What Is a Software Framework?</h2>
<p>The term framework can refer to a structure. It could be the structure of a system, a building, a project, or anything else.</p>
<p>You can now apply this definition in software engineering and refer to software frameworks as the structure for your software.</p>
<p>A software framework is a structure that you can use to build software. It acts as a foundation so you don't have to deal with creating unnecessary extra logic from scratch.</p>
<p>A framework is similar to a template in that you can modify it and add certain features and higher functionalities to create a complex and broad project that many people can use.</p>
<p><strong>Note:</strong> Software frameworks are typically associated with specific programming languages. They're also appropriate for various tasks depending on the situation.</p>
<p>You also have backend frameworks for backend tasks, frontend frameworks for frontend tasks, mobile frameworks for mobile tasks, and many others.</p>
<h2 id="heading-why-use-software-frameworks">Why Use Software Frameworks?</h2>
<p>Writing code is complex. And writing code that others can understand and manage is even more difficult because you must deal with syntax, declarations, performance, staying consistent, and other issues.</p>
<p>Software frameworks provide a template in which almost all general tasks have been handled. This allows you to focus on the core software development rather than the details of the process. Given that there is a set structure, it is simple to collaborate with others.</p>
<p>It's a good idea to use a software framework rather than re-inventing the wheel from scratch for numerous reasons. And perhaps the most important reason is that you won't have to write everything from scratch. This reduces the possibility of adding errors to your code.</p>
<p>Other reasons to use a framework include:</p>
<ul>
<li><p>It helps you avoid duplicate and redundant code.</p>
</li>
<li><p>It makes it easier for developers who did not write the code to test and debug it.</p>
</li>
<li><p>Frameworks are maintained by a group of people who test them so that you can use them with confidence.</p>
</li>
<li><p>They help you write clean and secure code</p>
</li>
<li><p>The time required to develop an application is significantly reduced because you can now focus on writing project-specific code.</p>
</li>
</ul>
<p>And a lot more.</p>
<h2 id="heading-types-of-software-frameworks">Types of Software Frameworks</h2>
<p>When you have a project to build or work on, you first decide on the programming language to use. Once you know the programming language, it's always best to look for frameworks that suit your needs.</p>
<p>There are many of these frameworks, each with unique characteristics that set them apart. You can find these frameworks in all areas of software engineering, including web development (frontend and backend), mobile applications, data science, and many others.</p>
<p>Let's look at some of the main types of software frameworks you'll come across in your development journey.</p>
<h3 id="heading-web-development-frameworks">Web Development Frameworks</h3>
<p>Web development involves creating a website that runs on the internet. This can be a single-page web application, a static website, a dynamic website, or anything else.</p>
<p>When creating these web pages, you usually have a frontend that the users see and a backend that controls and handles the logic (such as a database, API, and many other things).</p>
<p>Rather than list them all together, let's divide these frameworks into categories, so you know which to use when.</p>
<h4 id="heading-frontend-development-frameworks">Frontend Development Frameworks</h4>
<p><strong>React</strong> is a frontend JavaScript framework developed by Meta (previously Facebook). It helps you create user interfaces for websites and web applications. It is a popular framework that millions of developers worldwide use to create single-page applications (SPAs).</p>
<p>React uses Redux for state management and hooks to handle component behavior and logic. It also uses JSX to create HTML and CSS within JavaScript.</p>
<p>There are many helpful resources about React on the internet. You can <a target="_blank" href="https://www.freecodecamp.org/news/get-started-with-react-for-beginners/">learn more about React and how to get started in this guide</a>.</p>
<p><strong>Angular</strong> is a TypeScript-based framework developed by the Angular Team at Google. It is an open-source framework you can use to create single-page web applications, similar to React and Vue.</p>
<p>It has features such as two-way data binding, which reduces development time, and dependency injection, which makes it easier for different pieces of code to interact.</p>
<p>An enthusiastic community with numerous resources supports Angular. You can <a target="_blank" href="https://www.freecodecamp.org/news/learn-angular-full-course/">learn more about Angular and get started in this course</a>.</p>
<p><strong>Vue</strong> is a progressive JavaScript framework for creating user interfaces and single-page applications. It is easy to learn and pleasant to write in. It was built by Evan You, who previously worked at Google, to take the best parts of Angular and build a custom tool around it.</p>
<p>Vue3 is the latest version, which happens to be way faster and lighter than previous versions. It also comes with improved TypeScript support and many other features like the composition API.</p>
<p>You can learn more about <a target="_blank" href="https://www.freecodecamp.org/news/vue-js-full-course/">Vue and how to get started in the course</a>.</p>
<p><strong>Bootstrap</strong> is a framework that makes it easy for developers to build a fully responsive website or web application using a collection of reusable HTML, CSS, and JavaScript code. It has a group of pre-defined codes in a downloadable file or CDN that anyone can access and use.</p>
<p>You can learn more about <a target="_blank" href="https://www.freecodecamp.org/news/full-bootstrap-5-tutorial-for-beginners/">Bootstrap and how to use it in this course</a>.</p>
<p>There are many other frontend frameworks like Svelte, Semantic UI, and lots more. All these frameworks are used by famous companies like Netflix, Uber, Airbnb, and others.</p>
<h4 id="heading-backend-development-frameworks">Backend Development Frameworks</h4>
<p><strong>Django</strong> is a backend Python web framework that can work with any frontend framework. It helps developers focus on writing and building a significant project rather than re-inventing the wheel.</p>
<p>It's fast, secure, and scalable. You can learn more about <a target="_blank" href="https://www.freecodecamp.org/news/learn-django-3-and-start-creating-websites-with-python/">Django and how to get started building websites in this course</a>.</p>
<p><strong>Rails</strong> is an open-source backend framework like Django, powered by the Ruby language. It provides default structures for databases, web services, and web pages. It is designed to involve less code and repetition and is supported by a large community.</p>
<p>It is also known as Ruby on Rails. You can learn more about <a target="_blank" href="https://www.freecodecamp.org/news/learn-ruby-on-rails-video-course/">Rails and how to get started in this course</a>.</p>
<p>There are many other backend frameworks like Express, Laravel, and lots more. These frameworks are used to build websites and applications by famous companies like Twitter, Shopify, Coinbase, and others.</p>
<h3 id="heading-mobile-application-frameworks">Mobile Application Frameworks</h3>
<p><strong>Flutter</strong> is an open-source UI software development kit created by Google. It uses the Dart programming language and a little C/C++. You can use it to develop cross-platform applications for devices such as Android, Windows, Linux, macOS, iOS, the web, and lots more from a single codebase.</p>
<p>It was developed in 2017 and has since been used by big companies like Alibaba, BMW, and many more, as seen in the <a target="_blank" href="https://flutter.dev/showcase">Flutter showcase</a> web page. You can learn more and <a target="_blank" href="https://www.freecodecamp.org/news/learn-flutter-full-course/">get started with Flutter in this course</a>.</p>
<p><strong>React Native</strong> is an open source cross-platform Javascript framework developed by Meta. Cross-platform means that you can use it to develop Andriod, IOS, and web applications with one code base.</p>
<p>React Native uses the React framework and offers many inbuilt components and APIs. You can <a target="_blank" href="https://www.freecodecamp.org/news/create-an-app-that-works-on-ios-android-and-the-web-with-react-native-web/">learn more and get started with React Native in this course</a>.</p>
<p>There are many other mobile application frameworks like ionic, Xamarin, and lots more. These frameworks are used to build popular applications for famous companies like Discord, Bloomberg, and lots more.</p>
<h3 id="heading-data-science-frameworks">Data Science Frameworks</h3>
<p><strong>PyTorch</strong> is an open source machine learning framework based on the Python programming language and the Torch library. It is one of the preferred platforms for <strong>deep learning research</strong>. It is built to speed up the process between research prototyping and production deployment.</p>
<p>You can get started and <a target="_blank" href="https://www.freecodecamp.org/news/pytorch-full-course/">learn more about using PyTorch for deep learning in this course</a>.</p>
<p><strong>TensorFlow</strong> is a free and open-source Python library for machine learning and artificial intelligence developed by Google. It has a comprehensive, flexible ecosystem of tools, libraries, and community resources that lets researchers dive into machine learning. Developers can also use it to quickly build and deploy ML-powered applications.</p>
<p>You can learn more about <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-tensorflow-for-computer-vision/">TensorFlow and how it works with computer vision in this course</a>.</p>
<p>There are many other data science frameworks like Apache Spark, Scikit-learn, and lots more. Big companies like Microsoft, Cisco, Amazon, and others use these frameworks.</p>
<h2 id="heading-how-to-get-started-learning-a-software-framework">How to Get Started Learning a Software Framework</h2>
<p>So far, when discussing these frameworks, you will notice we also talk about specific programming languages. This should tell you that each framework relies heavily on a particular programming language.</p>
<p>You should have a solid understanding of the programming language a framework uses before learning that framework.</p>
<p>For example, if you want to learn React, you must first understand <a target="_blank" href="https://www.freecodecamp.org/news/top-javascript-concepts-to-know-before-learning-react/">JavaScript and some of its key concepts</a>. This is also true for other frameworks.</p>
<p>Finally, the better you understand a programming language, the more straightforward it'll be for you to grasp how frameworks function. Programming languages provide a solid foundation for many tech career paths and are critical for understanding a framework.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, you've learned what a software framework is, how they work, and how to get started learning any of them.</p>
<p>It is important to note that these are only a few of the many frameworks available. Almost every programming language has a framework designed to make using that language much more straightforward that'll allow you to focus on building your project.</p>
<p>It is always best to research which framework best suits your needs before beginning to build or write code.</p>
<p>Have fun coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Software Framework? ]]>
                </title>
                <description>
                    <![CDATA[ These days, companies both big and small use some kind of software framework to build their websites. And if you want to get into coding, it's important to learn and understand some of the popular frameworks – regardless of the field you choose in th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-software-framework/</link>
                <guid isPermaLink="false">66ba535a8e44e0cdf1281272</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Libraries ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tiago Capelo Monteiro ]]>
                </dc:creator>
                <pubDate>Wed, 13 Jul 2022 19:28:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/logo-freecodecamp.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>These days, companies both big and small use some kind of software framework to build their websites.</p>
<p>And if you want to get into coding, it's important to learn and understand some of the popular frameworks – regardless of the field you choose in the industry. ‌‌‌‌But why? ‌‌‌‌</p>
<p>Frameworks help you easily create new apps and ideas without having to write as much code yourself.</p>
<p>They also help eliminate a lot of headaches, so you can spend your time on what really counts.</p>
<p>Basically, they can be a real time saver.</p>
<p>In this article, we will explore:</p>
<ul>
<li>What is a framework?</li>
<li>What is a software framework?</li>
<li>Examples of software frameworks</li>
<li>The difference between a library and a framework</li>
</ul>
<p>So let's get started!</p>
<h2 id="heading-what-is-a-framework">What is a Framework?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/pexels-ludvig-hedenborg-axe.jpg" alt="Image" width="600" height="400" loading="lazy">
_Photo by [<strong>Pexels</strong>](https://www.pexels.com/@photolisious?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels" rel="noopener"&gt;<strong>Ludvig Hedenborg</strong> from &lt;a href="https://www.pexels.com/photo/brown-and-black-axe-3433348/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm<em>source=pexels" rel="noopener)</em></p>
<p>Imagine, if you will, a guy called John.</p>
<p>John needs to cut down a tree to light his fireplace up to make his family warm.</p>
<p>He goes into the woods, some time passes, and he finally chops down a tree.</p>
<p>Then, he needs to cut the tree into small pieces that can fit in his fireplace.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/pexels-ron-lach-anotheraxe.jpg" alt="Image" width="600" height="400" loading="lazy">
_Photo by [<strong>Pexels</strong>](https://www.pexels.com/@ron-lach?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels" rel="noopener"&gt;<strong>Ron Lach</strong> from &lt;a href="https://www.pexels.com/photo/axe-stuck-in-trunk-10397927/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm<em>source=pexels" rel="noopener)</em></p>
<p>Finally, John has successfully cut all the wood needed in the right size to warm his family.</p>
<h3 id="heading-but-what-if-john-had-a-chainsaw-instead">But, what if John had a chainsaw instead?</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/pexels-karolina-grabowska-chainsaw.jpg" alt="Image" width="600" height="400" loading="lazy">
_Photo by [<strong>Pexels</strong>](https://www.pexels.com/@karolina-grabowska?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels" rel="noopener"&gt;<strong>Karolina Grabowska</strong> from &lt;a href="https://www.pexels.com/photo/crop-lumberman-sawing-log-with-electric-power-saw-4205983/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm<em>source=pexels" rel="noopener)</em></p>
<p>‌If he had a chainsaw, the work would be done much more quickly and he would lose less time and energy cutting the wood for the fireplace.</p>
<p>Especially if he needed to chop down many trees.</p>
<p>But John likes to use his axe because he says it allows him more control over every <strong>bit</strong> of wood he chops off.</p>
<p>And with an axe he is able to cut small tree branches and it is better to chop up the wood.</p>
<p>So, with an axe, he can take care of minor things more easily. We don't need a tool like a chainsaw to do it. But when we're cutting down many big trees, it is a good idea to use a chainsaw, because it saves time and effort.</p>
<p>The same applies to coding. When we're programming and we just need to do simple stuff, it is better to just write our own code from scratch and/or get some libraries to help us with that.</p>
<p>But when we need to tackle many big projects, it is better to use a framework, because the project is big and frameworks can save us time.</p>
<p>According to the analogy:</p>
<ul>
<li>Cutting the tree with an axe = programming from scratch</li>
<li>Cutting trees with a chainsaw = Programming with a framework</li>
</ul>
<p>A chainsaw allows people to more <strong>easily cut trees.</strong></p>
<p>A framework allows people to more <strong>easily develop programs.</strong></p>
<h2 id="heading-what-is-a-software-framework">What is a Software Framework?</h2>
<p>Just as the chainsaw is a tool to work faster and more efficiently, a software framework is also a “tool” that helps a programmer work faster and achieve more in less time.</p>
<p>Just as there are many types of chainsaws, there are also many types of software frameworks.</p>
<h3 id="heading-examples-of-software-frameworks">Examples of software frameworks</h3>
<p>Now I'll share how and where you can use different frameworks in different areas of programming.</p>
<h4 id="heading-web-development-frameworks">Web development frameworks</h4>
<p>Web development frameworks make it easier to interact with the website database.</p>
<p>Frameworks automate functions and boring processes used to record and retrieve user-input data.</p>
<p>These frameworks can also make it easier to arrange and organize elements when you're designing the front-end of the site.</p>
<p>Vue is an example of a front-end web development framework.</p>
<p>Front-end means it is only the part the user sees – in other words, the <a target="_blank" href="https://www.freecodecamp.org/news/osi-model-networking-layers-explained-in-plain-english/">presentation layer</a> or OSI layer 6.</p>
<p>As a web development framework, Vue:</p>
<ul>
<li>Can <a target="_blank" href="https://vuejs.org/about/faq.html#does-vue-scale">Scale large applications</a></li>
<li><a target="_blank" href="https://vuejs.org/about/faq.html#should-i-use-javascript-or-typescript-with-vue=">Supports typescript</a></li>
<li><a target="_blank" href="https://router.vuejs.org/">Has its own router</a></li>
<li><a target="_blank" href="https://vuex.vuejs.org/">Has a state management library</a></li>
</ul>
<p>This is <a target="_blank" href="https://www.statista.com/statistics/1124699/worldwide-developer-survey-most-used-frameworks-web/">one of the most used frameworks</a> in the web development industry, along side with <a target="_blank" href="https://reactjs.org/">React</a> and <a target="_blank" href="https://angular.io/">Angular</a>.</p>
<p>The following organizations use Vue:</p>
<ul>
<li><a target="_blank" href="https://madewithvuejs.com/upwork">Upwork</a></li>
<li><a target="_blank" href="https://madewithvuejs.com/alibaba">Alibaba</a></li>
<li><a target="_blank" href="null">E</a><a target="_blank" href="https://madewithvuejs.com/euronews">uronews</a></li>
<li><a target="_blank" href="null">G</a><a target="_blank" href="https://madewithvuejs.com/google-careers">oogle careers</a> Platform</li>
</ul>
<p>I recommend Vue because I think it's easier to learn compared to other web development frameworks like <a target="_blank" href="https://reactjs.org/">React</a> and <a target="_blank" href="https://angularjs.org/">Angular</a>. Vue is also growing in popularity.</p>
<p>Normally, developers choose which framework they are going to use based on their team experience, the type of project their working on, or the complexity of their projects.</p>
<p>It really depends on your circumstances.</p>
<p>You can check out <a target="_blank" href="https://vuejs.org/">Vue's official site</a> for more information.</p>
<h4 id="heading-machine-learning-frameworks">Machine learning frameworks</h4>
<p>Machine learning frameworks help programmers by making it easy to implement complex ML algorithms in their programs.</p>
<p>You don't have to create these complex algorithms by yourself. Someone has already done it for you.</p>
<p>This makes your life easier as you just have to get your dataset, optimize the data to be used in the machine learning model, save the model, and run your analysis.</p>
<p>One of the most popular machine learning frameworks <a target="_blank" href="https://www.statista.com/statistics/793840/worldwide-developer-survey-most-used-frameworks/">worldwide</a> is <a target="_blank" href="https://pytorch.org/">PyTorch</a>.</p>
<p>PyTorch is a machine learning based on the <a target="_blank" href="http://torch.ch/">torch</a> library, developed by <a target="_blank" href="https://ai.facebook.com/research/">Facebook AI research lab</a>.</p>
<p>PyTorch has:</p>
<ul>
<li>Open Neural Network Exchange support</li>
<li>Hybrid Front-End</li>
<li>Dynamic Computational Graph Support</li>
<li>Data Parallelism</li>
</ul>
<p>PyTorch has been used in some cool projects, like:</p>
<ul>
<li>A<a target="_blank" href="https://pytorch.org/blog/amazon-ads-case-study/">mazon has reduce inference costs by 71% and drive scale out using PyTorch, TorchServe, and AWS Inferentia</a>.</li>
<li><a target="_blank" href="https://pytorch.org/">Stanford PyTorch’s flexibility to efficiently research new algorithmic approaches.</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=oBklltKXtDE">U</a>sed in tesla cars to detect traffic lights, crosswalks, roadsigns...</li>
</ul>
<p><a target="_blank" href="https://pytorch.org/ecosystem/">Many GitHub projects</a> use this framework, from computer vision to natural language processing applications.</p>
<p>I recommending PyTorch because it is easy to learn compared to other machine learning frameworks, it's written in Python, it has a big community around it, and so much more!</p>
<p>You can also check out <a target="_blank" href="https://www.tensorflow.org/">TensorFlow</a> and <a target="_blank" href="https://scikit-learn.org/stable/index.html">sci-kit-learn</a>, as they are also very popular.</p>
<p>Just keep in mind that TensorFlow and sci-kit-learn are both libraries, not frameworks. We'll discuss the difference more below.</p>
<p>In general, companies use TensorFlow, while machine learning researchers use PyTorch.</p>
<p>This is mainly for three reasons:</p>
<ul>
<li>Python's API hasn't changed much over the years compared to TensorFlow, so the code from some months back is almost the same in PyTorch. In Tensofrlow, it may be different or even not run at all.</li>
<li>The Tensorflow API has changed, but the documentation has not changed much, making it difficult for researchers to find online help.</li>
<li>Most research done by big companies is in PyTorch.</li>
</ul>
<p>So, if you are reading research in advanced stages, most of the code you see will be in PyTorch.</p>
<p>There are <a target="_blank" href="https://www.researchgate.net/post/Why_most_researchers_are_shifting_from_tensorFlow_to_Pytorch">many</a> more reasons for this, but these are just some examples.</p>
<p>Here is the website for PyTorch:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://pytorch.org/">https://pytorch.org/</a></div>
<h4 id="heading-mobile-development-frameworks">Mobile development frameworks</h4>
<p>Mobile development frameworks help programmers a lot by automating many tasks that would otherwise make maintaining projects a hassle.</p>
<p>For example, instead of using 50 lines of code to create a button or to better navigate the space in a screen, frameworks let you drop some button code in, ready to apply to your app.</p>
<p>With a framework a lot of that work is already done for you.</p>
<p><a target="_blank" href="https://reactnative.dev/">React native</a> is a mobile development framework based on the <a target="_blank" href="https://reactjs.org/">React</a> library.</p>
<p>This framework comes from the web version of React.</p>
<p>This mobile framework was one of the <a target="_blank" href="https://www.statista.com/statistics/869224/worldwide-software-developer-working-hours/">most popular</a> in the world from 2019 to 2021.</p>
<p>Its main features are:</p>
<ul>
<li>Seamless Cross-Platform Development</li>
<li>Fast Refresh</li>
<li>Code Reusability</li>
<li>Improved UI/UX</li>
<li>Hot Reload</li>
</ul>
<p>Just as with PyTorch, React Native has also been used to develop many projects:</p>
<ul>
<li><a target="_blank" href="https://instagram-engineering.com/react-native-at-instagram-dd828a9a90c7">Instagram</a></li>
<li><a target="_blank" href="https://medium.com/airbnb-engineering/whats-next-for-mobile-at-airbnb-5e71618576ab">Airbnb</a></li>
<li><a target="_blank" href="https://eng.uber.com/ubereats-react-native/">Uber eats</a></li>
<li><a target="_blank" href="https://medium.com/pinterest-engineering/supporting-react-native-at-pinterest-f8c2233f90e6">Pinterest</a></li>
</ul>
<p>I recommending React Native because it's based on React.</p>
<p>And if you know JavaScript and React well, you can easily develop cross platform apps.</p>
<p>There are also <a target="_blank" href="https://flutter.dev/">Flutter</a>, <a target="_blank" href="https://kivy.org/#home">kivy</a>, <a target="_blank" href="https://cordova.apache.org/">cordova</a>, and many more mobile development frameworks.</p>
<p>Compared to React native, flutter uses the <a target="_blank" href="https://dart.dev/">Dart programming language</a>, Kivy uses Python, and Cordova uses HTML, CSS, and JavaScript</p>
<p>With all of these frameworks, the best choice comes down to what knowledge you already have and the constraints placed on you by your company or team.</p>
<p>For example, if you already know how to use Python and want to develop a small personal project, maybe the best choice is Kivy.</p>
<p>If you join a company and work on the front end with React, is best choice is probably React Native.</p>
<p>Since there are many choices, it really come down to your requirements and projects.</p>
<p>Here is the website for React Native:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://reactnative.dev/">https://reactnative.dev/</a></div>
<p>These are just three types of frameworks you can look into. Also, keep in mind that there are many frameworks. I just showed you some of them here.</p>
<h2 id="heading-whats-the-difference-between-a-library-and-a-framework">What's the Difference Between a Library and a Framework?</h2>
<p>If you're new to coding, you might not know the differences between a library and a framework. But they're not the same thing.</p>
<p>A library is code from a collection of files that someone wrote pre-made for your project.</p>
<p>Like using a shovel. You can use it to dig whatever you want.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/pexels-anna-tarazevich-7299923.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Photo by Anna Tarazevich: https://www.pexels.com/photo/a-shovel-on-brown-dirt-ground-7299923/</em></p>
<p>A framework is like using an excavator. While you can dig more dirt with an excavator, you only use it for specific (big) construction projects.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/pexels-ilya-5328418.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Photo by Ilya: https://www.pexels.com/photo/construction-vehicles-at-work-5328418/</em></p>
<p>With a library, you are in control of the code. You use the library to add new features to help your project</p>
<p>With a framework, you are limited by it. You can only work with the "space" the framework gives you. There are also technical reasons for this, which you can <a target="_blank" href="https://www.freecodecamp.org/news/the-difference-between-a-framework-and-a-library-bd133054023f/">read more about in this article</a>.</p>
<h3 id="heading-should-i-use-a-framework-or-library-for-my-project">Should I use a framework or library for my project?</h3>
<p>It depends on the complexity of your project, who or what teams will maintain it, and so on.</p>
<p>By analogy, imagine that one of John's hobbies is wood carving.</p>
<p>To do that, he needs to use a simple set of tools to cut wood. He cannot use his axe.</p>
<p>While it can help in some phase of his project, it can also, by accident, destroy the project. It can't work in fine enough detail.</p>
<p>So in this case, the best thing to do is to do everything from scratch. The same applies to programming.</p>
<p>If you want to do a simple project, but need to use function you don't know how to create, you should use libraries.</p>
<p>If you want to work on a complex project where there are a lot of things you don't currently understand, a framework might help you get going.</p>
<p>Also keep in mind that if you work at a big company you might write the code without using any frameworks at all. This way, there is more space for programmers and engineers to develop projects without any limitations.</p>
<p>In many cases, simple programming projects are better the fewer library dependencies they have.</p>
<p>And in general, I believe that the more you code your projects yourself, the better the project is. At least in most cases. :)</p>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>Great! In this article you have learned:</p>
<ul>
<li>What a software framework is</li>
<li>3 different software frameworks and how to learn more about them</li>
<li>The differences between a software framework and software library</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use PyScript – A Python Frontend Framework ]]>
                </title>
                <description>
                    <![CDATA[ By Ifihanagbara Olusheye Python has grown in popularity immensely in recent years. It has a wide range of applications, from its most popular use in Artificial Intelligence, to Data Science, Robotics, and Scripting. In the web development field, Pyth... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/pyscript-python-front-end-framework/</link>
                <guid isPermaLink="false">66d45f333a8352b6c5a2aa61</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ front end ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 26 May 2022 15:37:08 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-26-at-13.28.49.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ifihanagbara Olusheye</p>
<p>Python has grown in popularity immensely in recent years. It has a wide range of applications, from its most popular use in Artificial Intelligence, to Data Science, Robotics, and Scripting.</p>
<p>In the web development field, Python is used mainly on the backend with frameworks such as Django and Flask.</p>
<p>Before now, Python didn't have much support on the front-end side like other languages such as JavaScript. But thankfully, Python developers have built some libraries (such as <a target="_blank" href="https://brython.info/">Brython</a>) to support their favourite language on the web.</p>
<p>And this year, during the <a target="_blank" href="https://youtube.com/playlist?list=PL2Uw4_HvXqvYeXy8ab7iRHjA-9HiYhRQl">PyCon 2022 conference</a>, Anaconda announced a framework named PyScript that allows you to use Python on the web using standard HTML.</p>
<p>You can check out this tweet about the launch:</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/anacondainc/status/1520447158603890691?s=20&amp;t=K-hrRhY9RwRaIkD-45acTQ"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p> </p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>You'll need the following tools and knowledge to code along with this article:</p>
<ul>
<li><p>A text editor or IDE of your choice.</p>
</li>
<li><p>Knowledge of Python.</p>
</li>
<li><p>Knowledge of HTML.</p>
</li>
<li><p>A browser (Google Chrome is the recommended browser for PyScript).</p>
</li>
</ul>
<h2 id="heading-what-is-pyscript">What is PyScript?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-22-at-18.29.40.png" alt="Image from PyScript's website." width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://pyscript.net/"><em>PyScript official website</em></a></p>
<p>PyScript is a Python front-end framework that enables users to construct Python programs using an HTML interface in the browser.</p>
<p>It was developed using the power of <a target="_blank" href="https://emscripten.org/">Emscripten</a>, <a target="_blank" href="https://pyodide.org/en/stable/">Pyodide</a>, <a target="_blank" href="https://webassembly.org/">WASM</a>, and other modern web technologies to provide the following abilities in line with its goals:</p>
<ul>
<li><p>To provide a simplistic and clean API.</p>
</li>
<li><p>To provide a system of pluggable and extensible components.</p>
</li>
<li><p>To support and extend standard HTML to read opinionated and dependable custom components in order to reach the mission “Programming for the 99%.”</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-26-at-11.27.01.png" alt="An image showing what PyScript is built on." width="600" height="400" loading="lazy"></p>
<p><em>Source:</em> <a target="_blank" href="https://www.anaconda.com/blog/pyscript-python-in-the-browser"><em>Anaconda Blog</em></a></p>
<p>In the last couple of decades, Python and advanced UI languages like modern HTML, CSS, and JavaScript have not worked in collaboration. Python lacked a simple mechanism to create appealing UIs for simply packaging and deploying apps, while current HTML, CSS, and JavaScript can have a steep learning curve.</p>
<p>Allowing Python to utilize HTML, CSS, and JavaScript conventions solves not only those two problems but also those related to web application development, packaging, distribution, and deployment.</p>
<p>PyScript isn't meant to take the role of JavaScript in the browser, though – rather, it's meant to give Python developers, particularly data scientists, more flexibility and power.</p>
<h2 id="heading-why-pyscript">Why PyScript?</h2>
<p>PyScript gives you a programming language with consistent styling conventions, more expressiveness, and ease of learning by providing the following:</p>
<ul>
<li><p><strong>Support on the browser:</strong> PyScript enables support for Python and hosting without the need for servers or configuration.</p>
</li>
<li><p><strong>Interoperability:</strong> Programs can communicate bi-directionally between Python and JavaScript objects and namespaces.</p>
</li>
<li><p><strong>Ecosystem support:</strong> PyScript allows the use of popular Python packages such as Pandas, NumPy, and many more.</p>
</li>
<li><p><strong>Framework flexibility:</strong> PyScript is a flexible framework that developers can build on to create extensible components directly in Python easily.</p>
</li>
<li><p><strong>Environment Management:</strong> PyScript allows developers to define the files and packages to include in their page code to run.</p>
</li>
<li><p><strong>UI Development:</strong> With PyScript, developers can easily build with available UI components such as buttons and containers, and many more.</p>
</li>
</ul>
<h2 id="heading-how-to-get-started-with-pyscript">How to Get Started with PyScript</h2>
<p>PyScript is fairly easy and straightforward to learn. To get started, you can either follow the instructions on the <a target="_blank" href="https://pyscript.net/">website</a> or download the <a target="_blank" href="https://github.com/pyscript/pyscript/archive/refs/heads/main.zip">.zip</a> file.</p>
<p>In this article, we'll be using and learning how to use PyScript via the <a target="_blank" href="https://pyscript.net/">website</a>. You can do this by linking the components in your HTML file. Let’s print our first “Hello World” with PyScript.</p>
<h3 id="heading-create-an-html-file">Create an HTML file</h3>
<p>To begin, you'll need to create an HTML file to display text on your browser using the text editor/IDE of your choice.</p>
<pre><code class="lang-HTML"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span>
          <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Title: PyScript<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-link-pyscript">Link PyScript</h3>
<p>After creating the HTML file, we'll need to link PyScript in your HTML file to have access to the PyScript interface. This will be placed in the <code>&lt;head&gt;</code> tag.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.css"</span> /&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<h3 id="heading-print-to-browser">Print to browser</h3>
<p>Now that you've linked PyScript to the HTML file, you can print your “Hello World”.</p>
<p>You can do this with the <code>&lt;py-script&gt;</code> tag. The <code>&lt;py-script&gt;</code> tag allows you to run multi-line Python programs and have them printed on the browser page. Place the tag in between the <code>&lt;body&gt;</code> tags.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">py-script</span>&gt;</span> print("Hello, World!") <span class="hljs-tag">&lt;/<span class="hljs-name">py-script</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>The full code for the HTML file is below:</p>
<pre><code class="lang-HTML"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span>
          <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Title: PyScript<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">py-script</span>&gt;</span> print("Hello, World!") <span class="hljs-tag">&lt;/<span class="hljs-name">py-script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>On your browser, you should see this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-23-at-18.19.48.png" alt="Image of the &quot;Hello, World&quot; on browser." width="600" height="400" loading="lazy"></p>
<p><strong>Tip:</strong> If you're using the VSCode editor, you can use the Live Server add-on in <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer">VSCode</a> to reload the page as you update the HTML file.</p>
<h2 id="heading-more-operations-with-pyscript">More Operations with PyScript</h2>
<p>There are more operations you can perform with the PyScript framework. Let's look at some of them now.</p>
<h3 id="heading-attach-labels-to-labeled-elements">Attach labels to labeled elements</h3>
<p>While using PyScript, you might want to pass variables from your Python code to HTML. You can do this with the <code>write</code> method from the <code>pyscript</code> module within the <code>&lt;pyscript&gt;</code> tag. Using the <code>id</code> attribute , you get to pass strings displayed as regular text.</p>
<p>The write method accepts two variables: the <code>id</code> value and the variable that will be provided.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.css"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Today is <span class="hljs-tag">&lt;<span class="hljs-name">u</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">id</span>=<span class="hljs-string">'today'</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">u</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">py-script</span>&gt;</span>
import datetime as dt
pyscript.write('today', dt.date.today().strftime('%A %B %d, %Y'))
    <span class="hljs-tag">&lt;/<span class="hljs-name">py-script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>And the output becomes:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-24-at-11.07.18.png" alt="Image showing the output of a date." width="600" height="400" loading="lazy"></p>
<h3 id="heading-run-repl-in-the-browser">Run REPL in the browser</h3>
<p>PyScript provides an interface for running Python code in browsers.</p>
<p>To be able to do this, PyScript uses the <code>&lt;py-repl&gt;</code> tag. The <code>&lt;py-repl&gt;</code> tag adds a REPL component to the page, which acts as a code editor and allows you to write executable code inline.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.css"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">py-repl</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"my-repl"</span> <span class="hljs-attr">auto-generate</span>=<span class="hljs-string">true</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">py-repl</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Trying it out in browser (preferably Chrome), you should get this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-24-at-16.14.34.png" alt="Python's REPL in browser." width="600" height="400" loading="lazy"></p>
<h3 id="heading-import-files-modules-and-libraries">Import Files, Modules, and Libraries</h3>
<p>One of the functions PyScript provides is flexibility. In PyScript you can import local files, inbuilt modules, or third-party libraries. This process uses the <code>&lt;py-env&gt;</code> tag. This tag is for declaring the dependencies needed.</p>
<p>For local Python files on your system, you can place the code in a <code>.py</code> file and the paths to local modules are provided in the paths: key in the <code>&lt;py-env&gt;</code> tag.</p>
<p>Let’s create a Python file <code>example.py</code> to contain some functions:</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> random <span class="hljs-keyword">import</span> randint

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add_two_numbers</span>(<span class="hljs-params">x, y</span>):</span>
    <span class="hljs-keyword">return</span> x + y

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">generate_random_number</span>():</span>
    x = randint(<span class="hljs-number">0</span>, <span class="hljs-number">10</span>)
    <span class="hljs-keyword">return</span> x
</code></pre>
<p>Then the Python file will be imported into the HTML with the <code>&lt;py-env&gt;</code> tag. You should place this tag in the the <code>&lt;head&gt;</code> tag, above the <code>&lt;body&gt;</code> tag.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.css"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">py-env</span>&gt;</span>
        - paths:
          - /example.py
      <span class="hljs-tag">&lt;/<span class="hljs-name">py-env</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's print random numbers<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">b</span>&gt;</span>Doe's lucky number is <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"lucky"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">b</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">py-script</span>&gt;</span>
      from example import generate_random_number
      pyscript.write('lucky', generate_random_number())
    <span class="hljs-tag">&lt;/<span class="hljs-name">py-script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>This will return:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/Screenshot-2022-05-24-at-23.20.31.png" alt="Printing out random numbers with Python." width="600" height="400" loading="lazy"></p>
<p>For third-party libraries that are not part of the standard library, PyScript supports them.</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.css"</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://pyscript.net/alpha/pyscript.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">py-env</span>&gt;</span>
            - numpy
            - requests
      <span class="hljs-tag">&lt;/<span class="hljs-name">py-env</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">py-script</span>&gt;</span>
    import numpy as np
    import requests
    <span class="hljs-tag">&lt;/<span class="hljs-name">py-script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-configure-metadata">Configure metadata</h3>
<p>You can set and configure general metadata about your PyScript application in YAML format using the <code>&lt;py config&gt;</code> tag. You can use this tag in this format:</p>
<pre><code class="lang-HTML"><span class="hljs-tag">&lt;<span class="hljs-name">py-config</span>&gt;</span>
  - autoclose_loader: false
  - runtimes:
    -
      src: "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"
      name: pyodide-0.20
      lang: python
<span class="hljs-tag">&lt;/<span class="hljs-name">py-config</span>&gt;</span>
</code></pre>
<p>These are the optional values that the <code>&lt;py-config&gt;</code> tag provides. They include:</p>
<ul>
<li><p><strong>autoclose_loader (boolean):</strong> If this is set to false, PyScript will not close the loading splash screen.</p>
</li>
<li><p><strong>name (string):</strong> Name of the user application.</p>
</li>
<li><p><strong>version (string):</strong> Version of the user application.</p>
</li>
<li><p><strong>runtimes (List of Runtimes):</strong> List of runtime configurations which would have the following fields: src, name, and lang.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned what PyScript is all about and how to use it in HTML files to run Python code on the browser. You also learned about the various operations/functionalities you can do with PyScript.</p>
<p>With PyScript, it’s easier to run and perform Python operations on the web, as this wasn’t easy before. This is a great tool for anyone who's looking forward to using Python on the web.</p>
<p>PyScript is still in its early stages and under heavy development. It is still in its alpha stage and faces known issues like the load time which can affect usability (some other operations can’t be shown at the time of this writing due to performance issues). So you shouldn't use it in production yet as there will likely be a lot of breaking changes.</p>
<h2 id="heading-references">References</h2>
<ul>
<li><p><a target="_blank" href="https://pyscript.net/">The PyScript official website</a>.</p>
</li>
<li><p><a target="_blank" href="https://www.anaconda.com/blog/pyscript-python-in-the-browser">Anaconda blog</a>.</p>
</li>
<li><p><a target="_blank" href="https://github.com/pyscript/pyscript">PyScript source code</a>.</p>
</li>
<li><p><a target="_blank" href="https://github.com/pyscript/pyscript/blob/main/docs/tutorials/getting-started.md">Guide on getting started with PyScript</a>.</p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Code a Framework – the  First Lines of Vue.js ]]>
                </title>
                <description>
                    <![CDATA[ By Fabio Pacific Have you ever wondered how frameworks are built? A couple of weeks ago I was writing an article and asked myself, what's the first line of code Evan You wrote to build Vue.js? Well, thanks to Git and Evan You pushing Vue's code to Gi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-code-a-framework-vuejs-example/</link>
                <guid isPermaLink="false">66d45ee7868774922c884fe0</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Vue.js ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 25 May 2022 21:38:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/pexels-hans-middendorp-9092855.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Fabio Pacific</p>
<p>Have you ever wondered how frameworks are built? A couple of weeks ago I was writing an article and asked myself, what's the first line of code Evan You wrote to build Vue.js?</p>
<p>Well, thanks to Git and Evan You pushing Vue's code to GitHub, I have been able to travel back in time, like Marty McFly with his DeLorean time machine. But I went nine years back, to 2013, and "watched" Evan writing his code. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/217316-Back_to_the_Future-DeLorean-time_travel-car-movies-smoke.jpg" alt="Delorean time machine" width="600" height="400" loading="lazy">
<em>Photo by wallup.net</em></p>
<h2 id="heading-whats-the-goal-of-this-article">What's the goal of this article?</h2>
<p>I am writing this article to show you what's behind a popular tool like Vuejs and what could be the starting point for building something like it. Specifically, we'll look at what was Evan's You starting point.</p>
<p>We will learn from Vue's creator by looking at the source code of his oldest commits. We'll examine what he wrote to make the first implementation of a Vue application and how he wrote the logic in plain JavaScript to make the mustache syntax work.</p>
<h3 id="heading-what-is-mustache-syntax">What is Mustache syntax?</h3>
<p>Well, if you are wondering what the hack is mustach syntax, let me explain. It is a basic form of data binding used by Vuejs to interpolate text inside a template. </p>
<p>From the vue documentation:</p>
<blockquote>
<p>Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying Vue instance’s data. The most basic form of data binding is text interpolation using the “Mustache” syntax (double curly braces):</p>
</blockquote>
<p><code>&lt;span&gt;Message: {{ msg }}&lt;/span&gt;</code></p>
<blockquote>
<p>The mustache tag will be replaced with the value of the msg property on the corresponding data object. It will also be updated whenever the data object’s msg property changes.</p>
</blockquote>
<p>Ok, now that you know what that is, in the next section I'll answer your next question...</p>
<h2 id="heading-what-will-i-learn-after-reading-this-article">What will I learn after reading this article?</h2>
<p>Ok fair enough, you want to know why should you read this article and what will you learn from it.</p>
<p>If you are either a seasoned Vuejs developer or just at the beginning of your journey, you will learn how everything started for a popular tool like Vue. </p>
<p>You will also learn how to hunt for a specific feature of a framework, browse old GitHub commits, and understand how you can apply plain JavaScript knowledge to start building the first features of one of the most popular frameworks of our time. </p>
<p>In the next section we will start exploring the Vue.js repository. We will look at the fist and second commits to understand what files were created for the initial setup of the framework. </p>
<p>This will help us find the feature that we are looking for (mustache syntax) and figure out also how the first Vue application was made.</p>
<h2 id="heading-exploring-vues-oldest-commits">Exploring Vue's Oldest Commits</h2>
<p>Alright, let's get started. If you want to follow me on this time traveling journey, hit this <a target="_blank" href="https://github.com/vuejs/vue/commits/0.6.0?after=218557cdec830a629252f4a9e2643973dc1f1d2d+349&amp;branch=0.6.0&amp;qualified_name=refs%2Ftags%2F0.6.0">link</a>. There, you'll find the Vuejs repository tagged 0.6.0. We are interested in its first and second commits.</p>
<p>I have downloaded a copy of the source code locally, precisely the source code of the second commit. Let's browse the code.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/jDeze8rA7cA" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-the-folder-structure">The Folder Structure</h2>
<p>The project structure in the second commit is fairly simple. Apart from a bunch of configuration files for jshing, grund, GitHub and the two JSON files, we can see three folders:</p>
<ul>
<li>test</li>
<li>src</li>
<li>explorations</li>
</ul>
<p>The last one is an addition Evan made. The exploration folder wasn't there on the first commit. And it is in there that the actual creation of Vue.js started to take place.</p>
<p>We will come back here later in the article, but before that let's look at the fist commit to find Evan's fist lines of code. Spolier: everything starts with a test.</p>
<h2 id="heading-the-first-vue-test-case">The First Vue Test Case</h2>
<p>The first lines of code are, I believe, those written in the test.js file. This is where Evan used the Mocha library to write Vue's first test case and set up the tests framework in the first commit named <a target="_blank" href="https://github.com/vuejs/vue/commits/0.6.0?after=218557cdec830a629252f4a9e2643973dc1f1d2d+349&amp;branch=0.6.0&amp;qualified_name=refs%2Ftags%2F0.6.0">initial setup</a>.</p>
<p>Why is this relevant? Well, we are not just hunting for a specific feature but we also want to understand what's the starting point for building a tool like Vuejs. </p>
<p>Do you start by writing the implementation? Or do you write a basic test case just to set everything up so that you can write proper tests when you have an idea of what you want to implement? </p>
<p>Well, below you have your answer!</p>
<p>Let's check the code of the test/test.js file:</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> Element = <span class="hljs-built_in">require</span>(<span class="hljs-string">'element'</span>)

describe(<span class="hljs-string">'Element'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    it(<span class="hljs-string">'should have a variable'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
        assert.equal(Element, <span class="hljs-number">123</span>)
    })
})
</code></pre>
<p>On the first line, there is a <code>require</code> statement to import an element class that will be defined somewhere later on in the code. Imagine this as the ancestor of the Vue class.</p>
<p>Next, the Mocha <code>describe</code> function is set to provide a general context.
Within it, an <code>it</code> function is called to write the actual test case that checks if the imported <code>Element</code> class is equal to <code>123</code>, which it does using the method <code>assert.equal()</code>.</p>
<p>To run the tests we will have to install all dependencies <code>npm i</code> and run the Grunt tasks. But since most of the libraries used are deprecated we won't do that (and this is also not the goal of this article and video).</p>
<p>In the next section, we will explore the second commit aiming to reach our goals – find the first implementation of Vue.js, and understand how the mustache syntax works.</p>
<p>To do that, we need to look at the second commit's source code, which is the one I have downloaded and am exploring on VSCode (if you are following the video as well).</p>
<p>Here is the <a target="_blank" href="https://github.com/vuejs/vue/tree/871ed9126639c9128c18bb2f19e6afd42c0c5ad9">direct link</a>.</p>
<h2 id="heading-the-first-vue-application">The First Vue Application</h2>
<p>In Vue, everything we do is done inside a Vue application, which is bound to an istance of the Vue class. So, we first need to find the first implementation of this class and in there we will find the logic behind the mustache syntax.</p>
<p>Ok, we need to look inside the explorations folder – here is where the magic happens.</p>
<p>The main file is called <code>getset-revitis-style.html</code>, and here we can see all the logic of the first Vue application (which you can find in the body tag) and its first implementation (which you can find in the <code>script</code> tag). </p>
<p>I made a copy of the entire file and placed everything inside an index.html file so we can mess around with the code, add some console logs, and explore how it works. </p>
<p>Let's serve the file using <code>serve -s</code>. (To run this command you will need to install an npm package. Just type in the terminal <code>npm install -g serve</code>.)</p>
<p>In the body tag we can see the Vue app, in <code>div</code> with an <code>id</code> of <code>test</code>. Today we either define our app inside a root element with an id of <code>app</code> or <code>root</code>, but at the time it started with a test div.</p>
<pre><code class="lang-html">
 <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"test"</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{msg}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{msg}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{msg}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{what}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{hey}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Inside the test <code>div</code> we can see the double mustache syntax. Cool! This is the first time it was used, but how does it work? </p>
<p>In the next section we will explore the first Vue class and look for the logic to make this <code>{{msg}}</code> work.</p>
<h2 id="heading-the-first-vue-instance">The First Vue Instance</h2>
<p>Ok, we found the firt usage of this syntax, but we are not done yet. We want to know how it works, remember? So, let's look in the script tag where we will find the logic of the first Vue class. </p>
<p>Evan created a class called <code>Element</code> – remember that we are nine years back in time, and ES6 isn't a thing until 2015.</p>
<p>The class declaration is written using <code>function Element () {}</code>. This is the ancestor class of what we know today as the Vue instance that we instantiate by doing <code>new Vue()</code>.</p>
<pre><code class="lang-js">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Element</span> (<span class="hljs-params">id, initData</span>) </span>{
  <span class="hljs-comment">// The first implementation is in here</span>
}
</code></pre>
<p>Next, the first Vue instance is created by instantiating the Element class:</p>
<pre><code class="lang-js">
<span class="hljs-keyword">var</span> app = <span class="hljs-keyword">new</span> Element(<span class="hljs-string">'test'</span>, {
  <span class="hljs-attr">msg</span>: <span class="hljs-string">'hello'</span>
})
</code></pre>
<p>The class expects an <code>id</code> and an <code>initData</code>. These are passed to the instance as the <code>test</code> value and as an object <code>{}</code> with a property called <code>msg</code>. This is our first implementation of the options object.</p>
<p>Ok, we are getting there. Now that we know how the class was implemented and instantiated, let's look inside to find how the double mustache syntax was implemented.</p>
<h2 id="heading-how-the-mustache-syntax-works">How the Mustache Syntax Works</h2>
<p>Here we are. The next code block will show us the syntax secrets. This is what we have been aiming to understand, the article's goal. </p>
<p>After this you will be able to understand what's behind this syntax and even edit and replace it with your own.</p>
<p>You could do something like <code>[[msg]]</code> and maybe call it the double box syntax. 🤓 </p>
<p>The code below is used to make the double mustache syntax work. In between there is more code that is responsible for how data are bound. </p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> bindingMark = <span class="hljs-string">'data-element-binding'</span> <span class="hljs-comment">// &lt;-- data binding mark </span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Element</span> (<span class="hljs-params">id, initData</span>) </span>{
<span class="hljs-comment">// The first implementation is in here</span>
  <span class="hljs-keyword">var</span> self = <span class="hljs-built_in">this</span>,
  el = self.el = <span class="hljs-built_in">document</span>.getElementById(id)
  <span class="hljs-comment">//console.log(self.el)</span>

  bindings = {} <span class="hljs-comment">// the internal copy</span>
  data = self.data = {} <span class="hljs-comment">// the external interface</span>
  content = el.innerHTML.replace(<span class="hljs-regexp">/\{\{(.*)\}\}/g</span>, markToken)

  el.innerHTML = content


  <span class="hljs-comment">// ....</span>

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">markToken</span>(<span class="hljs-params">match, variable</span>) </span>{
    <span class="hljs-built_in">console</span>.log(match) <span class="hljs-comment">// &lt;-- LOG match = {{msg}}</span>
    <span class="hljs-built_in">console</span>.log(variable) <span class="hljs-comment">// &lt;-- LOG captured group as variable = msg</span>
    <span class="hljs-comment">//console.log(bindings)</span>
    bindings[variable] = {}
    <span class="hljs-comment">//console.log(bindings)</span>

    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'&lt;span '</span> + bindingMark + <span class="hljs-string">'="'</span> + variable + <span class="hljs-string">'"&gt;&lt;/span&gt;'</span>)
    <span class="hljs-keyword">return</span> <span class="hljs-string">'&lt;span '</span> + bindingMark + <span class="hljs-string">'="'</span> + variable + <span class="hljs-string">'"&gt;&lt;/span&gt;'</span>
  }

  <span class="hljs-comment">// ...</span>
}
</code></pre>
<p>I have added a couple console logs to figure out what's inside two key parameters (<code>match</code> and <code>variables</code>) and what the <code>markToken</code> method returns.</p>
<p>Inside the script tag the fist line is a variable <code>var bindingMark = 'data-element-binding'</code>. This variable will be used as a data attribute and will replace the contents of the curly brackets using the replace method with a regular expression <code>el.innerHTML.replace(/\{\{(.*)\}\}/g, markToken)</code>. </p>
<p>Yes, you got it right – behind this syntax there is plain JavaScript and specifically one of the oldest methods built in the language.</p>
<p><code>string.replace()</code> is a string method that accepts two parameters:</p>
<ul>
<li>the regular expression</li>
<li>a callback function  </li>
</ul>
<p>Check the result of the regex using a site like  to see what matches the regex <code>\{\{(.*)\}\}</code>.</p>
<p>When the callback function <code>markToken</code> is called, we have access to the match and the captured group, respectively used as parameters called <code>match</code> and <code>variables</code>.</p>
<p>You can see these two parameter values using the console logs I added in the source code.</p>
<p>Inside the <code>markToken</code> method, the first line after the console logs is <code>bindings[variable] = {}</code>. This is an internal copy of the data that will be used later for the data binings feature of the framework. </p>
<p>For each match, it sets a new property in the <code>bindings</code> object as an empty object. For instance, if we have <code>{{msg}}</code> a new property called <code>binginds[msg] = {}</code> will be created.</p>
<p>Finally, the return statement builds a <code>span</code> element that uses the value of the <code>bindingMark</code> variable as a data attribute, <code>data-element-binding</code>
and assigns to it the <code>variable</code> parameter as property.</p>
<p>So, instead of <code>{{mess}}</code> the following string <code>'&lt;span ' + bindingMark + '="' + variable + '"&gt;&lt;/span&gt;'</code> is created. The result is the following code:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">data-element-binding</span>=<span class="hljs-string">"msg"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
</code></pre>
<p>The Vue code is still at its early stages. The implementation of the mustache syntax works alongside data bingind that is not yet fully implemented at this point of the framework.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we discovered the first steps Evan You took to build Vue.js. This is a raw implementation of the framework, and we have seen only a small bit of its code. But it can help us figure out how one of the framework features worked. And hey, things always start small to grow over time.</p>
<p>Let me know if you liked this kind of content. Reach out to me if you want to know what's behind a different feature of Vuejs. </p>
<p>You can also consider subscribing to my <a target="_blank" href="https://www.youtube.com/channel/UCTuFYi0pTsR9tOaO4qjV_pQ">YouTube channel</a>.</p>
<p>And you can follow me on <a target="_blank" href="https://twitter.com/Fab_Sky_Walker">Twitter</a> and <a target="_blank" href="https://www.linkedin.com/in/fabio-pacifici-com/">Linkedin</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Vue vs React – How to Go from One Framework to the Other ]]>
                </title>
                <description>
                    <![CDATA[ By Yiğit Kemal Erinç These days, a new trending front-end framework is released every now and then. But React and Vue.js still stand as the most popular among all the other alternatives.  And although both are performant, elegant, and arguably easy t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/vue-vs-react-comparison-of-frameworks/</link>
                <guid isPermaLink="false">66d45e4d052ad259f07e4aaf</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ vue ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 22 Oct 2021 21:59:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/pexels-ryutaro-tsukata-5472355.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Yiğit Kemal Erinç</p>
<p>These days, a new trending front-end framework is released every now and then. But React and Vue.js still stand as the most popular among all the other alternatives. </p>
<p>And although both are performant, elegant, and arguably easy to learn, they have some different opinions on how certain things should be done, and different ways of achieving the same end result.</p>
<p>I believe getting comfortable and efficient with a frontend framework is mostly about learning the patterns of doing regular stuff.</p>
<p>You know, how to listen to changes of a parameter/data and perform some action on that. And how to bind an event listener or data to an action object (button, checkbox, etc) and so on. </p>
<p>While I was working on a side-project with React, I noticed that my mind was like: "Yeah, I could do it like this in Vue, I would emit an event from the child, then listen for it in the parent and update this data". And then I was Googling how to do something like that in React.</p>
<p>In this article, I am going to show you how to apply some common patterns in both React and Vue that you'll come across in your daily front-end work. Then you can use these recipes to easily transition from one framework to the other one.</p>
<p>This will be helpful whether you are an experienced Vue developer who needs to work on a React project or the other way around. I will be using modern React with hooks and the Vue Options API (Vue 2). </p>
<p>I suggest cloning the <a target="_blank" href="https://github.com/yigiterinc/VueVsReact">repository</a> that contains all the code I use in this article and rendering the respective components in each section and playing with them to really understand how they work. </p>
<p>After cloning, you need to run <strong>npm install</strong> in the React and Vue folders. Then you can start the React project with <strong>npm start</strong> and the Vue project with <strong>npm run serve</strong>.</p>
<pre><code>https:<span class="hljs-comment">//github.com/yigiterinc/VueVsReact</span>
</code></pre><h3 id="heading-table-of-contents">Table of Contents</h3>
<ul>
<li><a class="post-section-overview" href="#heading-component-structure">Component Structure in React vs Vue</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-state">How to use State in React and Vue</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-props">How to Use Props in Vue and React</a></li>
<li><a class="post-section-overview" href="#heading-how-to-create-methodsfunctions">How to Create Methods/Functions in Vue and React</a></li>
<li><a class="post-section-overview" href="#heading-styling-options">Styling Options</a></li>
<li><a class="post-section-overview" href="#heading-how-to-bind-form-input-to-data-state">How to Bind Form Input to Data (State)</a></li>
<li><a class="post-section-overview" href="#heading-handling-events-user-input">How to Handle Events (User Input)</a></li>
<li><a class="post-section-overview" href="#heading-conditional-styling">Conditional Styling</a></li>
<li><a class="post-section-overview" href="#heading-conditional-rendering">Conditional Rendering</a></li>
<li><a class="post-section-overview" href="#heading-rendering-arrays-lists">Rendering Arrays (Lists)</a></li>
<li><a class="post-section-overview" href="#heading-child-to-parent-communication">Child to Parent Communication</a></li>
<li><a class="post-section-overview" href="#heading-reacting-to-datastate-changes">Reacting to Data/State Changes</a></li>
<li><a class="post-section-overview" href="#heading-computed-properties-vs-usememo">Computed Properties vs useMemo</a></li>
<li><a class="post-section-overview" href="#heading-vue-slots-vs-render-props">Vue Slots vs Render Props</a></li>
</ul>
<h2 id="1">Component Structure</h2>

<p>Let's take a bird's eye look into some very basic components in both frameworks. We will extend this in the following sections.</p>
<p>In Vue, a Single File Component contains 3 parts: the template, script and style.</p>
<p>The template is the part that will be rendered. It contains the HTML of the component and has access to the data (and methods) in the scripts and the styles.</p>
<p>You can find everything about a component inside these sections in Vue.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"structure"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello from Vue<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

&lt;!-- Use preprocessors via the lang attribute! e.g. &lt;style lang=<span class="hljs-string">"scss"</span>&gt; --&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-selector-id">#structure</span> {
  <span class="hljs-attribute">font-family</span>: Avenir, Helvetica, Arial, sans-serif;
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#2c3e50</span>;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">60px</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>To get this component rendered without a router or other complicated things, you can add it to <strong>App.vue.</strong> I suggest you render every component as you follow along so you can see them in action:</p>
<pre><code class="lang-js">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">structure</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">import</span> Structure <span class="hljs-keyword">from</span> <span class="hljs-string">'./Structure/Structure.vue'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">name</span>: <span class="hljs-string">'App'</span>,
  <span class="hljs-attr">components</span>: { Structure },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>You will be changing the import component inside the <strong>components</strong> section and the tag name in the <strong>template</strong> section.</p>
<p>In React, a functional component is a function that returns <a target="_blank" href="https://reactjs.org/docs/introducing-jsx.html">JSX</a> (an extension of JavaScript that allows you to use HTML tags inside JS code). You can think as if it is returning HTML to simplify things. The part that will be rendered used to be written inside the <code>render()</code> function in class-based React, if you are more familiar with that. </p>
<p>As you progress in this tutorial, in each section you can put the respective components inside App.js to get them rendered like this:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Structure</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Render me App<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Structure
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>

<span class="hljs-keyword">import</span> Structure <span class="hljs-keyword">from</span> <span class="hljs-string">'./Structure/Structure'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Structure</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App
</code></pre>
<p>So you will change the import and the component inside the div.</p>
<h2 id="2">How to Use State</h2>

<p>In Vue, we learned that the script tag contains the data and methods related to the component. The Vue Options API has special keywords (options) such as <em>data, methods, props, computed, watch,</em> and <em>mixins</em> that we can use, as well as lifecycle methods such as <em>created</em> and <em>mounted</em>. </p>
<p>We will use the <code>data</code> option to use state in our component. The data should be defined as a function which returns an object that contains our states. </p>
<p>To access the state inside our HTML (template), we have to use double curly braces and write the name of our variable. Keep in mind that any change to data variables will result in a render if that variable is used (referenced) in the HTML.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello {{ currentFramework }}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">currentFramework</span>: <span class="hljs-string">' Vue!'</span>,
      <span class="hljs-attr">alternative</span>: <span class="hljs-string">' React!'</span>,
    }
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

&lt;!-- Use preprocessors via the lang attribute! e.g. &lt;style lang=<span class="hljs-string">"scss"</span>&gt; --&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>In React, functional components used to be stateless. But thanks to hooks, we now have the <code>useState</code> hook to store state inside our component. To use the useState hook we have to import it, and the syntax is:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;


<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> [stateName, setStateName] = useState(<span class="hljs-string">'default value'</span>); 
}
</code></pre>
<p>We define the name of the state variable and name of its setter function inside the brackets, then we pass the default value of our variable to the useState hook. </p>
<p>You can imagine the hook like this to understand the syntax better: It is like a function that creates a variable, sets its value to the passed value, then returns an array which contains the variable and its setter function. </p>
<p>Note that you should use a single pair of curly parenthesis to switch to JavaScript scope and print a variable inside your JSX, instead of double parenthesis, which was the case with Vue.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">TestUseState</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [frameworkName, setFrameworkName] = useState(<span class="hljs-string">'React'</span>)

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>useState API<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Current Framework: {frameworkName}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> TestUseState
</code></pre>
<h2 id="3">How to Use Props</h2>

<p>In Vue, we define props by adding the props option inside the object we export inside the script field like we did with the data option. It is a best practice to define the props as objects so we get more control over how they are used. </p>
<p>For example, specify their types, default values, and make them required if necessary. Vue will show a warning if you use the component wrong, like calling it without passing a required prop. </p>
<p>Let's say we have an Address child component that will be called from the <code>UserInfo</code> parent component.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"address"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>City: {{ city }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Street: {{ street }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>House No: {{ houseNumber }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Postal Code: {{ postalCode }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {}
  },
  <span class="hljs-attr">props</span>: {
    <span class="hljs-attr">city</span>: {
      <span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,
      <span class="hljs-attr">default</span>: <span class="hljs-string">'Munich'</span>,
    },
    <span class="hljs-attr">street</span>: {
      <span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,
      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,
    },
    <span class="hljs-attr">houseNumber</span>: {
      <span class="hljs-attr">type</span>: <span class="hljs-built_in">Number</span>,
      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,
    },
    <span class="hljs-attr">postalCode</span>: {
      <span class="hljs-attr">type</span>: <span class="hljs-built_in">Number</span>,
      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>We can access our props just like our data variables – using the double parenthesis inside the template. And we can pass the props from the parent like this:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"address"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Name: Yigit<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Address</span>
      <span class="hljs-attr">street</span>=<span class="hljs-string">"randomStrasse"</span>
      <span class="hljs-attr">:postalCode</span>=<span class="hljs-string">"80999"</span>
      <span class="hljs-attr">:houseNumber</span>=<span class="hljs-string">"32"</span>
    &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Address</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">import</span> Address <span class="hljs-keyword">from</span> <span class="hljs-string">'@/components/Address.vue'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {}
  },
  <span class="hljs-attr">components</span>: {
    Address,
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Notice how we use the v-bind shorthand <code>:</code> and write <code>:postalCode</code> and <code>:houseNumber</code> to indicate that these are not strings but Number type objects. We have to use this syntax whenever we need to pass anything other than a string (array, object, number, and so on). </p>
<p>This might confuse you if you are coming from React, so you might want to read more about <a target="_blank" href="https://vuejs.org/v2/guide/class-and-style.html">v-bind</a> to get a better understanding of how it works.</p>
<p>In React, we do not need to explicitly define what props will be passed in the child component. We can either use object destructuring to assign props to variables or access them using the props object. We access our props inside JSX, just like how we access the state.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Address</span>(<span class="hljs-params">{ city, street, postalCode, houseNumber }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>City: {city}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Street: {street}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Postal Code: {postalCode}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>House Number: {houseNumber}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Address
</code></pre>
<p>And we can pass the props from the parent like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">UserInfo</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Name: Yigit<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Address</span>
        <span class="hljs-attr">city</span>=<span class="hljs-string">"Istanbul"</span>
        <span class="hljs-attr">street</span>=<span class="hljs-string">"Ataturk Cad."</span>
        <span class="hljs-attr">postalCode</span>=<span class="hljs-string">"34840"</span>
        <span class="hljs-attr">houseNumber</span>=<span class="hljs-string">"92"</span>
      &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Address</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> UserInfo
</code></pre>
<h2 id="4">How to Create Methods/Functions</h2>

<p>In Vue, we define methods similarly to data – we can just put a methods option under the data and define the method. We can call these methods from the template and methods can access/modify our data.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    {{ sayHello() }}
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">to</span>: <span class="hljs-string">'Methods'</span>,
    }
  },
  <span class="hljs-attr">methods</span>: {
    sayHello() {
      <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello '</span> + <span class="hljs-built_in">this</span>.to
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Be careful when trying to access component methods or data properties from inside the exported object (code inside script tag). If you don't include the <code>this</code> keyword, Vue will show an error saying it does not know where that property/method is.</p>
<p>In React, things are a bit more simple. It is just the regular JS function definition, with ES6 syntax, if you'd like.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">HelloFunctions</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> to = <span class="hljs-string">'Functions'</span>

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHello</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello '</span> + to
  }

  <span class="hljs-keyword">const</span> sayHelloModern = <span class="hljs-function">() =&gt;</span> <span class="hljs-string">'Hello '</span> + to

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      {sayHello()}
      <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
      {sayHelloModern()}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> HelloFunctions
</code></pre>
<h2 id="5">Styling Options</h2>

<p>Styling Vue components is really simple. We just need to write our plain old CSS classes and selectors inside the <code>style</code> tag. </p>
<p>Vue also supports scoped CSS by using the <code>scoped</code> keyword. It helps to avoid visual bugs caused by assigning the same class name inside different components. For example, you could name the main container in all your components <code>main-container</code> and only the styles in that component file would be applied to each main-container. </p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main-container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"label"</span>&gt;</span>I am a styled label<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {}
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">scoped</span>&gt;</span><span class="css">
<span class="hljs-selector-class">.main-container</span> {
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">45%</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>, -<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">text-align</span>: center;
}

<span class="hljs-selector-class">.label</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">300</span>;
  <span class="hljs-attribute">letter-spacing</span>: <span class="hljs-number">0.5rem</span>;
  <span class="hljs-attribute">text-transform</span>: uppercase;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>In React, though, we have more options in terms of styling and it's basically up to your personal preference since there are multiple ways to style your components. I will suggest a few good options here.</p>
<h3 id="heading-1-writing-regular-css-in-a-css-file-and-importing-it">1) Writing regular CSS in a .css file and importing it</h3>
<p>This is probably the most basic and straightforward approach for applying styles to your React components. It does not mean it is a bad approach, as it allows you to write plain old CSS. It is a good method if you are a CSS guru who is just getting started with React. </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'./styles.css'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Styled</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>I am red<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Styled
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: red;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
}
</code></pre>
<h3 id="heading-2-using-material-ui-usestylesmakestyles">2) Using Material UI (useStyles/makeStyles)</h3>
<p>Material UI is a CSS framework that has so many reusable components. It also provides a way to style your components, which uses CSS in JS and therefore has its advantages such as scoped CSS. </p>
<p>The <code>makeStyles</code> hook receives a list of classes in an object, then you can use those classes by assigning them to objects. </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { makeStyles } <span class="hljs-keyword">from</span> <span class="hljs-string">'@material-ui/core/styles'</span>;
<span class="hljs-keyword">import</span> Button <span class="hljs-keyword">from</span> <span class="hljs-string">'@material-ui/core/Button'</span>;

<span class="hljs-keyword">const</span> useStyles = makeStyles({
  <span class="hljs-attr">root</span>: {
    <span class="hljs-attr">background</span>: <span class="hljs-string">'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)'</span>,
    <span class="hljs-attr">border</span>: <span class="hljs-number">0</span>,
    <span class="hljs-attr">borderRadius</span>: <span class="hljs-number">3</span>,
    <span class="hljs-attr">boxShadow</span>: <span class="hljs-string">'0 3px 5px 2px rgba(255, 105, 135, .3)'</span>,
    <span class="hljs-attr">color</span>: <span class="hljs-string">'white'</span>,
    <span class="hljs-attr">height</span>: <span class="hljs-number">48</span>,
    <span class="hljs-attr">padding</span>: <span class="hljs-string">'0 30px'</span>,
  },
});

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Hook</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> classes = useStyles();
  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{classes.root}</span>&gt;</span>Hook<span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span></span>;
}
</code></pre>
<h3 id="heading-3-using-styled-components-css-in-js">3) Using Styled Components (CSS in JS)</h3>
<p><a target="_blank" href="https://styled-components.com/">Styled components</a> are modern and easy to use and it allows you to take advantage of all the features of plain CSS as well. </p>
<p>In my opinion, it is easier to use and more powerful than MaterialUI (you can also style MaterialUI components with this, instead of using <code>makeStyles</code>). It's also better than importing a CSS file since it is scoped and styled components are reusable.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> styled, { css } <span class="hljs-keyword">from</span> <span class="hljs-string">'styled-components'</span>

<span class="hljs-comment">// Use Title and Wrapper like any other React component – except they're styled!</span>
<span class="hljs-keyword">const</span> Title = styled.h1<span class="hljs-string">`
  font-size: 2em;
  text-align: center;
  color: palevioletred;
`</span>

<span class="hljs-comment">// Create a Wrapper component that'll render a &lt;section&gt; tag with some styles</span>
<span class="hljs-keyword">const</span> Wrapper = styled.section<span class="hljs-string">`
  padding: 4em;
  background: papayawhip;
  height: 100vh;
`</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">StyledComponent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Wrapper</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Title</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">Title</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Wrapper</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> StyledComponent
</code></pre>
<h2 id="6">How to Bind Form Input to Data (State)</h2>


<p>We have learned how to have state inside our components but we also need a way to bind user inputs to that state. For example in login forms, we will probably need to store the user's username and password input in the component state. React and Vue have different ways of keeping user inputs in sync with state.</p>
<p>In Vue we have a special directive for this operation called <a target="_blank" href="https://vuejs.org/v2/guide/forms.html">v-model</a>. To use this, you need to create a state by using the <code>data</code> property as we have learned before. Then you add the v-model keyword to your input and specify which data variable is responsible for storing this input (this is applicable to form input, textarea and select elements). </p>
<p>This is a high-level and clean way to connect data, removing the need to create additional lambda functions or handlers. </p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"inputState"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
    {{ inputState }}
    <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"changeInputState()"</span>&gt;</span>Click to say goodbye<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">inputState</span>: <span class="hljs-string">'Hello'</span>,
    }
  },
  <span class="hljs-attr">methods</span>: {
    <span class="hljs-attr">changeInputState</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">this</span>.inputState = <span class="hljs-string">'Goodbye'</span>
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Here is a small example: we have a text input, and we connect it to the <code>inputState</code> variable by using the v-model keyword. So whenever the user inputs text, the <code>inputState</code> variable will reflect the changes automatically. </p>
<p>However, there is one special thing that you need to know: v-model implements <strong>2-way data binding</strong> in contrast to <strong>1-way binding</strong> in React. </p>
<p>This means that, not only when you change the input does the data change, but also, if you change the data, the input value changes as well. </p>
<p>To demonstrate this, I have created a button and connected it to a method. Don't worry about the event handling yet, we will see that in next section. When the button is clicked, the value of inputState variable is changed and the input also changes when that happens. </p>
<p>I encourage you to try it yourself by running the code. Also, notice that the initial value of your input box is 'Hello' – it is not initialized to empty string or null because we set the <code>inputState</code> variable to 'Hello'.</p>
<p>Now let's see it in React:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">FormInputBinding</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [userInput, setUserInput] = useState(<span class="hljs-string">'Hello'</span>)

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setUserInput(e.target.value)} /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setUserInput('Goodbye')}&gt;
        Click to say goodbye
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      {userInput}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> FormInputBinding
</code></pre>
<p>This topic overlaps with handling user events so if you do not understand something, wait until you complete the next section. Here, we handle the <code>onChange</code> event manually and call the <code>setUserInput</code> function to set the state to the event's value. </p>
<p>As we mentioned earlier, React uses a <strong>1-way binding</strong> model. This means that changing the userInput state will not affect the value we see inside the text input – we won't see Hello inside the input box initially. Also when we click the button, it will update the state but the input inside the box will maintain its value.</p>
<h2 id="7">Handling Events (User Input)</h2>

<p>Let's see another form that is closer to real-life cases in Vue and React:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
      <span class="hljs-attr">v-model</span>=<span class="hljs-string">"username"</span>
      <span class="hljs-attr">id</span>=<span class="hljs-string">"outlined-basic"</span>
      <span class="hljs-attr">label</span>=<span class="hljs-string">"Username"</span>
      <span class="hljs-attr">variant</span>=<span class="hljs-string">"outlined"</span>
    /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
      <span class="hljs-attr">v-model</span>=<span class="hljs-string">"password"</span>
      <span class="hljs-attr">id</span>=<span class="hljs-string">"outlined-basic"</span>
      <span class="hljs-attr">type</span>=<span class="hljs-string">"password"</span>
      <span class="hljs-attr">label</span>=<span class="hljs-string">"Password"</span>
      <span class="hljs-attr">variant</span>=<span class="hljs-string">"outlined"</span>
    /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
      <span class="hljs-attr">v-model</span>=<span class="hljs-string">"termsAccepted"</span>
      <span class="hljs-attr">id</span>=<span class="hljs-string">"outlined-basic"</span>
      <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span>
      <span class="hljs-attr">label</span>=<span class="hljs-string">"Password"</span>
      <span class="hljs-attr">variant</span>=<span class="hljs-string">"outlined"</span>
    /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">variant</span>=<span class="hljs-string">"contained"</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"primary"</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"submitForm"</span>&gt;</span>
      Submit
    <span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">username</span>: <span class="hljs-string">''</span>,
      <span class="hljs-attr">password</span>: <span class="hljs-string">''</span>,
      <span class="hljs-attr">termsAccepted</span>: <span class="hljs-literal">false</span>,
    }
  },
  <span class="hljs-attr">methods</span>: {
    <span class="hljs-attr">submitForm</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.username, <span class="hljs-built_in">this</span>.password, <span class="hljs-built_in">this</span>.termsAccepted)
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>As you can see, we are using the v-model property that we just learned about to connect all our inputs to data properties (state). So, whenever the inputs change, Vue automatically updates the corresponding variable. </p>
<p>To see how we handle a click event on button, check the submit Button. We use the <a target="_blank" href="https://vuejs.org/v2/guide/events.html">v-on</a> keyword to handle click event. <code>@click</code> is just a shorthand for <code>v-on:click</code>.</p>
<p>Whenever a click event happens it simply calls the <code>submitForm</code> method. You can familiarize yourself with the list of possible events by going through the linked docs.</p>
<p>In React, we can have a form like this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">import</span> {
  TextField,
  Checkbox,
  FormControlLabel,
  Button,
} <span class="hljs-keyword">from</span> <span class="hljs-string">'@material-ui/core'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">EventHandling</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">let</span> [username, setUsername] = useState(<span class="hljs-string">''</span>)
  <span class="hljs-keyword">let</span> [password, setPassword] = useState(<span class="hljs-string">''</span>)
  <span class="hljs-keyword">let</span> [termsAccepted, setTermsAccepted] = useState(<span class="hljs-literal">false</span>)

  <span class="hljs-keyword">const</span> submitForm = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(username, password, termsAccepted)
  }

  <span class="hljs-keyword">const</span> formContainer = {
    <span class="hljs-attr">display</span>: <span class="hljs-string">'flex'</span>,
    <span class="hljs-attr">flexDirection</span>: <span class="hljs-string">'column'</span>,
    <span class="hljs-attr">alignItems</span>: <span class="hljs-string">'center'</span>,
    <span class="hljs-attr">gap</span>: <span class="hljs-string">'20px'</span>,
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{formContainer}</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">TextField</span>
        <span class="hljs-attr">onInput</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setUsername(e.target.value)}
        id="outlined-basic"
        label="Username"
        variant="outlined"
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">TextField</span>
        <span class="hljs-attr">onInput</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setPassword(e.target.value)}
        id="outlined-basic"
        type="password"
        label="Password"
        variant="outlined"
      /&gt;

      <span class="hljs-tag">&lt;<span class="hljs-name">FormControlLabel</span>
        <span class="hljs-attr">control</span>=<span class="hljs-string">{</span>
          &lt;<span class="hljs-attr">Checkbox</span>
            <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span>
            <span class="hljs-attr">checked</span>=<span class="hljs-string">{termsAccepted}</span>
            <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setTermsAccepted(e.target.checked)}
          /&gt;
        }
        label="Accept terms and conditions"
      /&gt;

      <span class="hljs-tag">&lt;<span class="hljs-name">Button</span> <span class="hljs-attr">variant</span>=<span class="hljs-string">"contained"</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"primary"</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> submitForm()}&gt;
        Submit
      <span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> EventHandling
</code></pre>
<p>We create our state variables for each input. We can then listen to events on inputs and the event will be accessible inside the handler function. We call the state setters to update our state as a response to these events. </p>
<h2 id="8">Conditional Styling</h2>

<p>Conditional Styling means binding a class or style to an element if a condition is true. </p>
<p>In Vue it can be achieved like this:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"toggleApplyStyles"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">"{ textStyle: stylesApplied }"</span>&gt;</span>
      Click the button to {{ stylesApplied ? 'unstyle' : 'style' }} me
    <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">stylesApplied</span>: <span class="hljs-literal">false</span>,
    }
  },
  <span class="hljs-attr">methods</span>: {
    <span class="hljs-attr">toggleApplyStyles</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">this</span>.stylesApplied = !<span class="hljs-built_in">this</span>.stylesApplied
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-selector-class">.textStyle</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">25px</span>;
  <span class="hljs-attribute">color</span>: red;
  <span class="hljs-attribute">letter-spacing</span>: <span class="hljs-number">120%</span>;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>We create a paragraph and want to apply the <code>textStyle</code> class only when the <code>stylesApplied</code> data property's value is true. We can use v-bind to achieve this. The colon is the shorthand for v-bind so <code>:class</code> is same as <code>v-bind:class</code>. </p>
<p>We use v-bind object syntax to bind classes. We pass an object to the class property: {textStyle: stylesApplied}, which means apply the <code>textStyle</code> class if <code>stylesApplied</code> is true. </p>
<p>It is a bit complicated at the start but it helps us avoid multiple chained if statements to determine which class will be applied and handles style bindings in a clean way: class names on the left (object keys), conditions on the right (object values).</p>
<p>In React we have to do things more primitively.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'./styles.css'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ConditionalStyling</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">let</span> [stylesApplied, setStylesApplied] = useState(<span class="hljs-literal">false</span>)

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setStylesApplied(!stylesApplied)}&gt;Click me<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">color:</span> <span class="hljs-attr">stylesApplied</span> ? '<span class="hljs-attr">red</span>' <span class="hljs-attr">:</span> '<span class="hljs-attr">green</span>' }}&gt;</span>Red or Green<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{stylesApplied</span> ? '<span class="hljs-attr">styleClass</span>' <span class="hljs-attr">:</span> ''}&gt;</span>Red with class<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> ConditionalStyling
</code></pre>
<p>Here we use plain JavaScript to bind either a styles object or a class name to the element. I think this complicates the code a bit, and I'm not a huge fan of this syntax.</p>
<h2 id="9">Conditional Rendering</h2>

<p>Sometimes, we want to render a component after some operation – such as fetching data from an API – is completed. Or maybe we want to display an error message if there is an error or success message if not. </p>
<p>For such situations, we use conditional rendering to change the HTML to be rendered programmatically. </p>
<p>In Vue, there are <a target="_blank" href="https://vuejs.org/v2/guide/conditional.html">special directives</a> for that as well. We can use the <code>v-if</code> and <code>v-else</code> or even <code>v-else-if</code> for rendering templates based on conditions.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">"condition1"</span>&gt;</span>condition1 is true<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">v-else-if</span>=<span class="hljs-string">"condition2"</span>&gt;</span>condition2 is true<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">v-else</span>&gt;</span>all conditions are false<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">condition1</span>: <span class="hljs-literal">false</span>,
      <span class="hljs-attr">condition2</span>: <span class="hljs-literal">false</span>,
    }
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>This syntax allows us to create complex chains of conditional rendering without complicating our template code with if else statements.</p>
<p>Here is one of the ways to accomplish the same output with React:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ConditionalRendering</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> condition1 = <span class="hljs-literal">false</span>
  <span class="hljs-keyword">const</span> condition2 = <span class="hljs-literal">false</span>

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getMessage</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">let</span> message = <span class="hljs-string">''</span>

    <span class="hljs-keyword">if</span> (condition1) {
      message = <span class="hljs-string">'condition1 is true'</span>
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (condition2) {
      message = <span class="hljs-string">'condition2 is true'</span>
    } <span class="hljs-keyword">else</span> {
      message = <span class="hljs-string">'all conditions are false'</span>
    }

    <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{message}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
  }

  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;&gt;</span>{getMessage()}<span class="hljs-tag">&lt;/&gt;</span></span>
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> ConditionalRendering
</code></pre>
<p>This is just plain JS and JSX, no magic here.</p>
<h2 id="10">Rendering Arrays (Lists)</h2>

<p>Now let's see how we can render list data. In Vue, there is <code>v-for</code> keyword for doing this. The syntax <strong>name in names</strong> means the name variable will always hold the current name. As the index changes, if index is 0, it is <code>names[0]</code> and so on. We can also access the index as specifying it inside the parentheses. The <strong>v-for</strong> directive also requires a key.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Names<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"(person, index) in people"</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">"index"</span>&gt;</span>{{ person.name }}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">people</span>: [
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">0</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Yigit'</span>,
        },
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">1</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Gulbike'</span>,
        },
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">2</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Mete'</span>,
        },
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">3</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Jason'</span>,
        },
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">4</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Matt'</span>,
        },
        {
          <span class="hljs-attr">id</span>: <span class="hljs-number">5</span>,
          <span class="hljs-attr">name</span>: <span class="hljs-string">'Corey'</span>,
        },
      ],
    }
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>Note that we can also use the <strong>v-for</strong> directive for iterating over properties of an object. Remember that, in JS, arrays are just a special subset of objects with number keys. </p>
<p>In React, we will use the <code>Arrays.map</code> function to iterate over the array and return a JSX tag for each element.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">RenderingLists</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> cities = [
    <span class="hljs-string">'Istanbul'</span>,
    <span class="hljs-string">'München'</span>,
    <span class="hljs-string">'Los Angeles'</span>,
    <span class="hljs-string">'London'</span>,
    <span class="hljs-string">'San Francisco'</span>,
  ]

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Cities<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      {cities.map((city, index) =&gt; (
        <span class="hljs-tag">&lt;<span class="hljs-name">h4</span> <span class="hljs-attr">key</span>=<span class="hljs-string">{index}</span>&gt;</span>{city}<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
      ))}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> RenderingLists
</code></pre>
<h2 id="11">Child to Parent Communication</h2>

<p>Imagine you have a form component and a button sub-component inside it. And you want to perform some action when that button is clicked, like calling an API to submit data – but you do not have access to the form data in the button component since it is stored in the parent. What do you do?</p>
<p>Well, if you are in Vue, you want to emit a custom event from the child and act on that in the parent. In React, you would create the function that will be executed (when button is clicked) in the parent, where the function has access to form data and pass it to the button component so that it can call the parent's function. </p>
<p>Let's see an example in Vue:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"buttonClicked"</span>&gt;</span>Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">methods</span>: {
    <span class="hljs-attr">buttonClicked</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">this</span>.$emit(<span class="hljs-string">'buttonClicked'</span>) <span class="hljs-comment">// Emits a buttonClicked event to parent</span>
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>In our child component, we have the button and on click we emit a <code>buttonClicked</code> event. We could also send data in this call. For example if this was a text input box instead of a button and had its own data, we could send that data to the parent with emit. </p>
<p>In the parent component, we need to listen for the custom <code>buttonClicked</code> event that we just created.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"#"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">child</span> @<span class="hljs-attr">buttonClicked</span>=<span class="hljs-string">"handleButtonClicked"</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">import</span> Child <span class="hljs-keyword">from</span> <span class="hljs-string">'./Child.vue'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">components</span>: { Child },
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">username</span>: <span class="hljs-string">''</span>,
    }
  },
  <span class="hljs-attr">methods</span>: {
    <span class="hljs-attr">handleButtonClicked</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.username)
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>We just added a <code>@buttonClicked</code> event to our child component call to handle this custom event. </p>
<p>In React, we could achieve the same results by passing a handler function to the child component. The concept was a bit complicated to me first but the syntax is easier than the Vue example and there is no magic.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Child</span>(<span class="hljs-params">{ handleButtonClicked }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> handleButtonClicked()}&gt;Submit<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Child
</code></pre>
<p>We access the <code>handleButtonClicked</code> prop and call it when the button is clicked.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-keyword">import</span> Child <span class="hljs-keyword">from</span> <span class="hljs-string">'./Child.js'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Parent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [username, setUsername] = useState(<span class="hljs-string">''</span>)

  <span class="hljs-keyword">const</span> submitForm = <span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(username)
    <span class="hljs-comment">// Post form data to api...</span>
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setUsername(e.target.value)} type="text" /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">Child</span> <span class="hljs-attr">handleButtonClicked</span>=<span class="hljs-string">{submitForm}</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Parent
</code></pre>
<p>In the parent, we pass the <code>submitForm</code> function as the <code>handleButtonClicked</code> prop which will do the job.</p>
<h2 id="12">Reacting to Data/State Changes</h2>

<p>In some cases, we need to react to data changes. For example, when you want to perform asynchronous or expensive operations in response to a change in data.</p>
<p> In Vue, we have <code>watch</code> properties or watchers for that. If you are familiar with <code>useEffect</code> in React, this is closest thing you can find in Vue and their use cases are more or less the same.</p>
<p>Let's see an example:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"number1"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"number"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"number 1"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"number2"</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"number"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"number 2"</span> /&gt;</span>
    {{ sum }}
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">number1</span>: <span class="hljs-number">0</span>,
      <span class="hljs-attr">number2</span>: <span class="hljs-number">0</span>,
      <span class="hljs-attr">sum</span>: <span class="hljs-number">0</span>,
    }
  },
  <span class="hljs-attr">watch</span>: {
    <span class="hljs-attr">number1</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) </span>{
      <span class="hljs-built_in">this</span>.sum = <span class="hljs-built_in">parseInt</span>(val) + <span class="hljs-built_in">parseInt</span>(<span class="hljs-built_in">this</span>.number2)
    },
    <span class="hljs-attr">number2</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">val</span>) </span>{
      <span class="hljs-built_in">this</span>.sum = <span class="hljs-built_in">parseInt</span>(<span class="hljs-built_in">this</span>.number1) + <span class="hljs-built_in">parseInt</span>(val)
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Here, we have <code>number1</code> and <code>number2</code> defined in our data properties. We have 2 respective inputs and we are printing the sum of those numbers and we want sum to update when any of the inputs change. </p>
<p>Inside the <code>watch</code> property, we write the name of the variable we want to <strong>watch</strong>. In this case, we want to watch both number1 and number2. If the user enters an input, <code>v-model</code> will change the corresponding data variable and when that happens, the <strong>watch</strong> function for that variable will be triggered and the value of sum will be recalculated.</p>
<p>Note that, in a real application, you wouldn't need to use watch for this simple thing and you would just put sum inside <code>computed</code> instead. This is a made-up example to demonstrate how <code>watch</code> works. </p>
<p>Before using <code>watch</code> with more complicated things like objects, arrays, and nested structures, I suggest reading <a target="_blank" href="https://michaelnthiessen.com/how-to-watch-nested-data-vue/">this article</a> because you will probably need to learn some <code>watch</code> options like <code>deep</code> and <code>immediate</code>.</p>
<p>In React, we use the built-in <code>useEffect</code> hook to watch for changes.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { React, useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ReactToDataChanges</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [number1, setNumber1] = useState(<span class="hljs-number">0</span>)
  <span class="hljs-keyword">const</span> [number2, setNumber2] = useState(<span class="hljs-number">0</span>)
  <span class="hljs-keyword">const</span> [sum, setSum] = useState(<span class="hljs-number">0</span>)

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'I am here!'</span>)
    setSum(<span class="hljs-built_in">parseInt</span>(number1) + <span class="hljs-built_in">parseInt</span>(number2))
  }, [number1, number2])

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setNumber1(e.target.value)}
        type="number"
        name="number 1"
      /&gt;
      <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
        <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> setNumber2(e.target.value)}
        type="number"
        name="number 2"
      /&gt;
      {sum}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> ReactToDataChanges
</code></pre>
<p><code>useEffect</code> expects a function to run when a dependency changes as the first argument and a list of dependencies as the second argument. </p>
<p>Keep in mind that this is also a made-up example to demonstrate <code>useEffect</code> (we could achieve the same without <code>useEffect</code> by taking the sum variable out of state).</p>
<p>I want to show a very common use case for this hook: fetching data from an API after the component loads:</p>
<pre><code class="lang-javascript">useEffect(<span class="hljs-function">() =&gt;</span> {
    fetchUserData()
}, [])

<span class="hljs-keyword">const</span> fetchUserData = <span class="hljs-keyword">async</span> () =&gt; {
    <span class="hljs-keyword">const</span> url = <span class="hljs-string">''</span>;
    <span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> axios.get(url);
    <span class="hljs-keyword">const</span> user = response.data;
    setUser(user);
}
</code></pre>
<p>We can specify empty array to run the <code>useEffect</code> once when the component renders. In Vue, we would do the same operation inside a lifecycle hook, such as <code>created</code> or <code>mounted</code>.</p>
<h2 id="13">Computed Properties vs useMemo</h2>

<p>Vue has a concept called computed properties, which serve the purpose of caching rather complex computations and re-evaluating their values whenever one of the dependencies change (similar to <code>watch</code>). </p>
<p>It is also useful in keeping our templates clean and concise by moving the logic to <strong>JavaScript</strong>. In this case, they act like regular variables which we don't want to be a state.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Yigit's Favorite Cities are:<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"city in favCities"</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">"city"</span>&gt;</span>{{ city }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Yigit's Favorite Cities in US are:<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"town in favCitiesInUS"</span> <span class="hljs-attr">:key</span>=<span class="hljs-string">"town"</span>&gt;</span>{{ town }}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"addBostonToFavCities"</span>&gt;</span>
      Why is Boston not in there? Click to add
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">computed</span>: {
    <span class="hljs-attr">favCitiesInUS</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.favCities.filter(<span class="hljs-function">(<span class="hljs-params">city</span>) =&gt;</span> <span class="hljs-built_in">this</span>.usCities.includes(city))
    },
  },
  data() {
    <span class="hljs-keyword">return</span> {
      <span class="hljs-attr">favCities</span>: [
        <span class="hljs-string">'Istanbul'</span>,
        <span class="hljs-string">'München'</span>,
        <span class="hljs-string">'Los Angeles'</span>,
        <span class="hljs-string">'Rome'</span>,
        <span class="hljs-string">'Florence'</span>,
        <span class="hljs-string">'London'</span>,
        <span class="hljs-string">'San Francisco'</span>,
      ],
      <span class="hljs-attr">usCities</span>: [
        <span class="hljs-string">'New York'</span>,
        <span class="hljs-string">'Los Angeles'</span>,
        <span class="hljs-string">'Chicago'</span>,
        <span class="hljs-string">'Houston'</span>,
        <span class="hljs-string">'Phoenix'</span>,
        <span class="hljs-string">'Arizona'</span>,
        <span class="hljs-string">'San Francisco'</span>,
        <span class="hljs-string">'Boston'</span>,
      ],
    }
  },
  <span class="hljs-attr">methods</span>: {
    addBostonToFavCities() {
      <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.favCities.includes(<span class="hljs-string">'Boston'</span>)) <span class="hljs-keyword">return</span>

      <span class="hljs-built_in">this</span>.favCities.push(<span class="hljs-string">'Boston'</span>)
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Here, we do not want to put the <code>favCitiesInUS</code> function inside our template because it is too much logic. </p>
<p>Think of it like a function where the output will be cached. The function will be re-evaluated only if <code>favCities</code> or <code>usCities</code> (its dependencies) changes. To try that, you can click the button and see how the template changes. Keep in mind that computed functions do not receive any arguments.</p>
<p>We can use the <code>useMemo</code> hook to achieve the same result in React. We wrap the function in the useMemo hook and provide the list of dependencies in the second argument. Whenever one of those dependencies changes, React will run the function again.</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> { React, useMemo, useState } from <span class="hljs-string">'react'</span>

<span class="hljs-function">function <span class="hljs-title">UseMemoTest</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">const</span> [favCities, setFavCities] = useState([
      <span class="hljs-string">'Istanbul'</span>,
      <span class="hljs-string">'München'</span>,
      <span class="hljs-string">'Los Angeles'</span>,
      <span class="hljs-string">'Rome'</span>,
      <span class="hljs-string">'Florence'</span>,
      <span class="hljs-string">'London'</span>,
      <span class="hljs-string">'San Francisco'</span>,
    ]),
    [usCities, setUsCities] = useState([
      <span class="hljs-string">'New York'</span>,
      <span class="hljs-string">'Los Angeles'</span>,
      <span class="hljs-string">'Chicago'</span>,
      <span class="hljs-string">'Houston'</span>,
      <span class="hljs-string">'Phoenix'</span>,
      <span class="hljs-string">'Arizona'</span>,
      <span class="hljs-string">'San Francisco'</span>,
      <span class="hljs-string">'Boston'</span>,
    ])

  <span class="hljs-keyword">const</span> favCitiesInUs = useMemo(() =&gt; {
    <span class="hljs-keyword">return</span> favCities.filter((city) =&gt; usCities.includes(city))
  }, [favCities, usCities])

  <span class="hljs-keyword">return</span> (
    &lt;div&gt;
      &lt;h3&gt;Yigit<span class="hljs-string">'s Favorite Cities are:&lt;/h3&gt;
      {favCities.map((city) =&gt; (
        &lt;p key={city}&gt;{city}&lt;/p&gt;
      ))}
      &lt;h3&gt;Yigit'</span>s Favorite Cities in US are:&lt;/h3&gt;
      {favCitiesInUs.map((town) =&gt; (
        &lt;p key={town}&gt;{town}&lt;/p&gt;
      ))}
      &lt;button onClick={() =&gt; setFavCities([...favCities, <span class="hljs-string">'Boston'</span>])}&gt;
        Click me to add
      &lt;/button&gt;
    &lt;/div&gt;
  )
}

export <span class="hljs-keyword">default</span> UseMemoTest
</code></pre>
<h2 id="14">Vue Slots vs Render Props</h2>

<p>We sometimes want to create generic components that can display other components inside of them, such as a grid component that displays any type of item inside it.</p>
<p>For that purpose, Vue has a mechanism called <a target="_blank" href="https://twitter.com/caglarcilara/status/1448905192045531143?s=20">slots</a>. The logic behind slots is really simple: you open a slot in the component which should receive another component to render (let's call it consumer, because it consumes the elements that are provided). </p>
<p>In the producer, you pass the components that consumer should render inside its tags – you can think of them as filling the slots you opened in the consumer. The first element will be rendered in the first slot, the second in the second slot, and so on. </p>
<p>If there is more than one slot, you have to set the names as well. Let's see an example:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Component in slot 1:<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"slot1"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Hello slot1<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"slot2"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Component in slot 3:<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"slot3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Here is our consumer component. It may be creating a layout or some composition from multiple components. We create the slots and give them distinct names.</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">consumer</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">custom-button</span>
        <span class="hljs-attr">text</span>=<span class="hljs-string">"I am a button in slot 1"</span>
        <span class="hljs-attr">slot</span>=<span class="hljs-string">"slot1"</span>
      &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">custom-button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"slot2"</span>&gt;</span>I am in slot 2, yayyy<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">custom-button</span> <span class="hljs-attr">text</span>=<span class="hljs-string">"I am in slot 3"</span> <span class="hljs-attr">slot</span>=<span class="hljs-string">"slot3"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">custom-button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">consumer</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">import</span> CustomButton <span class="hljs-keyword">from</span> <span class="hljs-string">'./CustomButton.vue'</span>
<span class="hljs-keyword">import</span> Consumer <span class="hljs-keyword">from</span> <span class="hljs-string">'./Consumer.vue'</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">components</span>: {
    CustomButton,
    Consumer,
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>And here is the producer passing the components to the slots of consumer by specifying their slot name as an attribute.</p>
<p>And here is the simple <code>CustomButton</code> component if you are interested in that:</p>
<pre><code class="lang-javascript">&lt;template&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>{{ text }}<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
&lt;/template&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">props</span>: {
    <span class="hljs-attr">text</span>: {
      <span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,
      <span class="hljs-attr">default</span>: <span class="hljs-string">'I am a button component'</span>,
    },
  },
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>
</code></pre>
<p>Can you guess the output without running the code? That might be a good exercise to make sure you understand slots.</p>
<p>In React, it is much simpler. I think the slots overcomplicate things a lot. As React uses JSX, we can just get away with passing the component to be rendered as a prop.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>
<span class="hljs-keyword">import</span> Child <span class="hljs-keyword">from</span> <span class="hljs-string">'./Child'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Parent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> compToBeRendered = (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Im button<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Child</span> <span class="hljs-attr">compToBeRendered</span>=<span class="hljs-string">{compToBeRendered}</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Child</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Parent
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Child</span>(<span class="hljs-params">{ compToBeRendered }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>In child:<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      {compToBeRendered}
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Child
</code></pre>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>In this last section of the article, I would like to share my two cents on these frameworks. </p>
<p>As we have seen through the article, Vue usually has its own way of doing things and has different constructs for most things. Sometimes this makes it a bit harder to get started with in my opinion. </p>
<p>On the other hand, React is like pure JS, blended with JSX: not much magic and not many special keywords to learn. </p>
<p>Although it may be not be the most beginner-friendly framework, I believe that the abstractions/keywords Vue provides (such as v-for, v-if and the Options API) allow you to write code at a higher level of abstraction (think of adding a simple statement to iterate over components versus a low level, multi-line map function).</p>
<p>These features also make your Vue code more structured and clean because the framework is opinionated. So it has its own ways of doing things, and if you do things that way, you will end up with code that is easy to read and understand.</p>
<p>React, on the other hand, is not very opinionated about things and provides developers with a lot of freedom to decide the structure of their project themselves.</p>
<p>But this freedom comes with a cost: if you are a beginner who is not aware of best practices, it is easy to end up with messy code and a poorly structured project. </p>
<p>Another important difference in my opinion is this: if you are going to build a non-fundamental project with React, you will need to use a lot of external libraries to develop at a normal speed, which means you will need to learn how those things work as well.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thank you for reading and I hope this comparison was useful. If you would like to connect, ask questions, or discuss further, feel free to send me a message on <a target="_blank" href="https://www.linkedin.com/in/yigit-erinc/">LinkedIn</a>. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Is React a Library or a Framework? Here's Why it Matters ]]>
                </title>
                <description>
                    <![CDATA[ Developers have spent a great deal of time talking about what React is. But they have left out why this topic matters so greatly for anyone who builds React applications. The answer to this question is essential for any React developer, regardless of... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/is-react-a-library-or-a-framework/</link>
                <guid isPermaLink="false">66d0379764be048ac359a323</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Libraries ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Reed ]]>
                </dc:creator>
                <pubDate>Mon, 12 Apr 2021 21:29:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/04/is-react-a-library-or-framework.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Developers have spent a great deal of time talking about what React is. But they have left out why this topic matters so greatly for anyone who builds React applications.</p>
<p>The answer to this question is essential for any React developer, regardless of their skill level. This is because it indicates what they must know and how they must work in developing any React application.</p>
<p>Whether you are a new or an advanced React developer, I hope this thoughtful analysis will improve your own development process as you build your next React project.</p>
<h2 id="heading-why-is-react-a-library-and-not-a-framework">Why is React a library and not a framework?</h2>
<p>React was made to build full-fledged web applications. As a result, it's often compared with other tools that developers use to build apps, like Angular, Vue, and Svelte. </p>
<p>React is written in JavaScript and is used to make better JavaScript applications. We refer to React specifically as a <strong>library</strong>. </p>
<p><em>But what makes React a library and not a framework?</em> </p>
<p>The reason becomes clear when we look at other similar tools that are used to create complete web applications.</p>
<p>Let's look at a project like Angular, which shares the same purpose as React (to create single-page web apps). What sets it apart is the fact that when you set up an Angular project, it is bootstrapped with nearly every single thing that you'll need to make a complete, large-scale app. </p>
<blockquote>
<p>Many developers like to refer to frameworks or similar solutions as having "batteries included." </p>
</blockquote>
<p>Frameworks are a common choice for companies and anyone looking to make enterprise JavaScript applications, because they include resources that a large-scale application would likely need. This includes built-in tools for common tasks like creating forms, running automated tests, making network requests, and much more.</p>
<p>In short, everything that you need to make a complete application is included in your Angular project when it's generated. But that is not the case with React.</p>
<h2 id="heading-react-is-fundamentally-unopinionated">React is fundamentally "unopinionated"</h2>
<p>While popular tools have emerged like Create React App, which allow you to create a complete React project in a single command, React is often referred to as "unopinionated." </p>
<p><em>What does it mean for React to be unopinionated?</em></p>
<p>The React and React DOM libraries give us the means of building a user interface with the JSX syntax, plus powerful state management tools via hooks, among other things.</p>
<p>However, React itself does not include many of the React-specific libraries you're going to need for most projects. Angular and Vue, by comparison, include many more tools all bundled within the core package itself.</p>
<p>Many developers consider this discussion of what is and isn't a library to be trivial. But it has real consequences for our development process. In other words, because React is a library and not a framework, <strong>becoming a skilled React developer entails having a good knowledge of third-party React libraries</strong>.</p>
<h2 id="heading-since-react-is-a-library-you-must-choose-the-tools-on-your-own">Since React is a library, you must choose the tools on your own</h2>
<p>That means, in order to build complete React applications, you will need to choose these packages and tools on your own. </p>
<p>Here are a few examples of decisions that I often need to make when I'm building a React application myself: </p>
<p>For a form library, I have to decide whether I want to use the package React Hook Form or Formik. These are both React-specific form libraries to add important features to our forms like validation.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/react-form-libraries.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>For testing my React application, I might use either React Testing Library, Jest, or some combination of the two.</p>
<p>For making network requests, I might need to choose between the Fetch API and Axios. I might also need to decide if I want to add an additional library to make managing my server state easier, such as React Query or SWR.</p>
<h2 id="heading-the-tools-you-choose-depend-on-your-app-and-knowledge-of-them">The tools you choose depend on your app and knowledge of them</h2>
<p>This question of whether React is a library or framework is important because any React developer must know what their choices are and which choice to make given the type of React application they're building.</p>
<p>If you're building an app without many forms, you might not need a form library at all. If you're more confident with the Fetch API, you might use that over something like Axios. </p>
<p>It really depends not only on what the demands of the app are, but also on what your preferences are as a developer. This is arguably an advantage that React has as a library and why I believe it's very popular among newer developers. It doesn't lock you into one choice or hold you to any specific libraries other than React itself. </p>
<p>You're able to make your own decisions, and you're able to have more freedom overall, as a developer. </p>
<p>That being said, even though React is not a framework this does not diminish its presence in the corporate realm. It's still used to build complex and impressive applications of all kinds. There are many lists of the large-scale React applications that businesses have made and which you likely use on a daily basis.</p>
<h2 id="heading-you-need-to-keep-up-with-emerging-libraries">You need to keep up with emerging libraries</h2>
<p>If we were talking about which form library to choose two years ago, I would likely have included Redux Form. As for a data fetching library, I couldn't have mentioned React Query or SWR, because they weren't created (or hadn't gained much traction), until the last year or so.</p>
<p>Because React apps are often reliant upon third-party libraries, newer libraries come about that improve upon the old ones. Individual developers and teams transition to different tools to get the job done and the ecosystem changes as a whole.</p>
<p>Like it or not, React being a library and not a framework entails a large, shifting network of other libraries we must be aware of to build our projects. Some of which may fall out of favor and be replaced by others or may become deprecated and no longer supported as open-source projects. </p>
<p>In short, React being a library may require us to pay more attention to what is going on <em>around</em> React, as compared to if it was a framework.</p>
<h2 id="heading-wish-react-was-a-framework-there-are-many">Wish React was a framework? There are many!</h2>
<p>It's worth noting that there are frameworks out there that are based upon React. </p>
<p>While React itself is just a library, many React-based frameworks have cropped up in recent years to provide developers with a more powerful set of built-in tools. These allow you to build projects faster without needing as many third-party libraries. </p>
<p>Some of the most popular of these frameworks include Next.js, Gatsby, and Redwood.js, all of which are used to create full-scale dynamic and static React applications.</p>
<p>This is, in my opinion, the great advantage of frameworks – you do not have to make as many choices throughout the development process.</p>
<h2 id="heading-use-reacts-flexibility-to-your-advantage">Use React's flexibility to your advantage</h2>
<p>Be aware that going forward, there is a robust ecosystem of React-focused libraries that you can add to your React project to achieve whatever you're looking for, from the most general tasks to the most specific. </p>
<p>This is thanks to React's popularity and widespread usage. But also note, especially if you're coming from an opinionated framework like Angular or Vue, that there are many React-based frameworks that you can rely upon and learn about to build equally functional and featureful applications as well.</p>
<h2 id="heading-become-a-professional-react-developer">Become a Professional React Developer</h2>
<p>React is hard. You shouldn't have to figure it out yourself.</p>
<p>I've put everything I know about React into a single course, to help you reach your goals in record time:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><strong>Introducing: The React Bootcamp</strong></a></p>
<p><strong>It’s the one course I wish I had when I started learning React.</strong></p>
<p>Click below to try the React Bootcamp for yourself:</p>
<p><a target="_blank" href="https://www.thereactbootcamp.com"><img src="https://reedbarger.nyc3.digitaloceanspaces.com/reactbootcamp/react-bootcamp-cta-alt.png" alt="Click to join the React Bootcamp" width="600" height="400" loading="lazy"></a>
<em>Click to get started</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why You Should Use React.js For Web Development ]]>
                </title>
                <description>
                    <![CDATA[ By Suraj Surve If you are new to React.js, you must be wondering why it is so popular and why you should use it in your applications. If so, then you are in the right place.  Let's discuss what makes React.js so great and why you should use it ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-use-react-for-web-development/</link>
                <guid isPermaLink="false">66d4614a47a8245f78752acc</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 18 Feb 2021 19:20:34 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/02/React-js-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Suraj Surve</p>
<p>If you are new to React.js, you must be wondering why it is so popular and why you should use it in your applications. If so, then you are in the right place. </p>
<p>Let's discuss what makes React.js so great and why you should use it in your projects.</p>
<h1 id="heading-table-of-contents">Table of Contents</h1>
<ul>
<li>A Brief History of React.js</li>
<li>Why Should You USe React?</li>
<li>React is Flexible</li>
<li>React Has a Great Developer Experience</li>
<li>React Has Facebook's Support/Resources</li>
<li>React Also Has Broader Community Support</li>
<li>React Has Great Performance</li>
<li>React is Easy to Test</li>
</ul>
<h2 id="heading-a-brief-history-of-reactjs">A Brief History of React.js</h2>
<p>Facebook created <a target="_blank" href="https://reactjs.org/">React.js</a> in 2011 for their own use. As you know, Facebook is one of the biggest Social Networking websites in the world today.</p>
<p>In 2012, Instagram also started using it, which is a subsidiary of Facebook.</p>
<p>In 2013, Facebook made React.js open-sourced. Initially, the developer community rejected it because it used Markup and JavaScript in a single file. But as more people experimented with it, they started embracing the component-centric approach for separating concerns.</p>
<p>In 2014, many large companies started using React.js in their production environments.</p>
<p>In 2015, Facebook open-sourced <a target="_blank" href="https://reactnative.dev/">React Native</a> too. It is a library that allows us to create native mobile apps in Android and iOS using React.js.</p>
<p>In 2016, with version 15, React.js started using Semantic Versioning. This also helped convey to the developer's community that React was more stable.</p>
<p>Today, React.js is used by many <strong>Fortune 500</strong> companies. Facebook has full-time React development staff. They regularly release bug fixes, enhancements, blog posts, and documentation.</p>
<h2 id="heading-why-should-you-use-react">Why Should You Use React?</h2>
<p>You must be wondering why you should use React.js. After all, as the <a target="_blank" href="https://www.tutorialfunda.com/js/introduction-javascript-and-modern-uses/">uses of JavaScript</a> have increased in recent years, we now have multiple options available in the market like <a target="_blank" href="https://angular.io/">Angular</a> and <a target="_blank" href="https://vuejs.org/">Vue.js</a>. So, why React?</p>
<p>Let's explore six key reasons to use React.js.</p>
<h2 id="heading-react-is-flexible">React is Flexible</h2>
<p>React is remarkably flexible. Once you have learned it, you can use it on a vast variety of platforms to build quality user interfaces. React is a library, NOT a framework. Its library approach has allowed React to evolve into such a remarkable tool.</p>
<p>React was created with a single focus: to create components for web applications. A <a target="_blank" href="https://www.freecodecamp.org/news/how-to-write-better-react-components/">React component</a> can be anything in your web application like a Button, Text, Label, or Grid.</p>
<p>But as React's popularity is grown, its ecosystem has also grown to cover various use cases.</p>
<p>You can generate a static site with React using tools like <a target="_blank" href="https://www.gatsbyjs.com/">Gatsby</a>. You can use React Native to build mobile apps. You can even create Desktop applications using a tool like <a target="_blank" href="https://www.electronjs.org/">Electron</a>, which can run on mac and windows with React.js technology.</p>
<p>React also supports server rendering of its components using tools like <a target="_blank" href="https://nextjs.org/">Next.js</a>. You can also use React.js to create a virtual reality website and 360 experiences using React VR.</p>
<blockquote>
<p>"Learn React Once and Write Everywhere" - Reactjs.org</p>
</blockquote>
<p>You can use React in your existing apps too. React was designed keeping this in mind. You can change a small part of your existing application by using React, and if that change works, then you can start converting your whole application into React.js. Facebook used the same approach.</p>
<blockquote>
<p>"The main advantage of using a Library over a Framework is that Libraries are lightweight, and there is a freedom to choose different tools. The Framework consists of an entire ecosystem to build an application, and you don't have <em>an easy way</em> to use any other tools outside the Framework."</p>
</blockquote>
<h2 id="heading-react-has-a-great-developer-experience">React Has a Great Developer Experience</h2>
<p>Your team will fall in love with React when they start coding in it. Rapid development and React's small API combined creates a fantastic developer experience.</p>
<p>React's API is very simple to learn. It has very few concepts to learn. Here is a small example of a React Component:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/React-Component.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>React Component</em></p>
<p>You just need to import the React library. <strong>Message</strong> is the component that accepts props (input) and returns JSX.</p>
<p>JSX is a special syntax that looks like HTML, which converts React's API calls and finally renders HTML.</p>
<p>Traditional frameworks like Angular and Vue power up the HTML. They use JavaScript inside HTML. They have created HTML attributes that give extra capabilities to it. </p>
<p>The main problem with this approach is that you have to learn those new HTML attributes or always keep looking at the official documentation.</p>
<p>Here's an example of looping in Angular. Look at the <strong>*ngFor</strong> attribute:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/Angular-Loops.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Angular Loops Example (Source : <a target="_blank" href="https://angular.io/">Angular</a>)</em></p>
<p>And here's an example of looping in Vue.js. Look at the <strong>v-for</strong> attribute:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/vue-looping.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Vue Loops Example (Source :<a target="_blank" href="https://vuejs.org/"> vuejs.org</a>)</em></p>
<p>React uses the opposite approach. It uses HTML (JSX) inside JavaScript. I like this approach because here, you can deal with pure JavaScript and HTML.</p>
<p>Here's an example of looping in React.js</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/loops-in-React.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>React Loops Example (Source : <a target="_blank" href="https://reactjs.org/">Reactjs.org</a>)</em></p>
<p>The React component <strong>NumberList</strong> is using pure JavaScript code (the map function). Also, you can see that JSX is a simple well-known HTML tag with no fancy attributes. The render function is simply rendering the NumberList component in the root element in the HTML file.</p>
<p>What else you need as a developer if you have the platform where you can deal with pure JavaScript and HTML and still build an interactive UI?</p>
<p><strong>Note:</strong> <em>When I say "pure JavaScript" that doesn't mean you will use vanilla JavaScript in React. React is a JavaScript Library, and it has its layer on top of the Javascript. BUT, as I said, the React API is very small and simple to learn. Angular &amp; Vue force their rules on you. React is more conceptual. It shows you how you can make better use of vanilla JavaScript in the React way.</em></p>
<p>React.js also gives us the <a target="_blank" href="https://www.freecodecamp.org/news/how-to-build-a-react-project-with-create-react-app-in-10-steps/">create-react-app package</a>, which allows you to start development instantly.</p>
<h2 id="heading-react-has-facebooks-supportresources">React Has Facebook's Support/Resources</h2>
<p>React is heavily used in the Facebook app, website, and in Instagram. That's why Facebook is deeply committed to it. They use over 50k React components in their production environment. The top four React contributors on GitHub are full-time Facebook employees.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/React-js-Top-Contributors.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Top React.js Contributors</em></p>
<p>Also, the React team maintains a <a target="_blank" href="https://reactjs.org/blog/all.html/">blog</a> that consistently gives you details for each release. </p>
<p>Because of the deep commitment by Facebook to React in production, when breaking change occur in React, Facebook consistently provides <a target="_blank" href="https://github.com/reactjs/react-codemod">Codemod</a> that automates the change.</p>
<p>Codemod is the command-line tool that automates changes to your codebase. When a new specification comes into React, Codemod automatically replaces older components with the newer specification.</p>
<h2 id="heading-react-has-broader-community-support-too">React Has Broader Community Support, Too</h2>
<p>Since 2015, React's popularity has grown steadily. It has a massive active community and its <a target="_blank" href="https://github.com/facebook/react">GitHub Repository</a> has over 164k Stars. It is one of the Top 5 Repositories on GitHub.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/React-Git-Repository.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>React Git Repository.</em></p>
<p>React's <a target="_blank" href="https://www.npmjs.com/package/react">NPM package</a> has millions of weekly downloads as well.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/React-NPM-Package-Downlaods.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Over 9K companies reported on <a target="_blank" href="https://stackshare.io/react">Stackshare</a> that they are using React. You can even see Fortune 500 companies.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/Stackshare-React.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>Companies Using React</em></p>
<p><a target="_blank" href="https://www.reactiflux.com/">Reactiflux</a> is a community specially made for React Developers. Over 110k community members are involved in helping solve and share React-related problems.</p>
<p>One of the most popular websites among software developers is <a target="_blank" href="https://stackoverflow.com/">StackOverflow</a>. You can see that there are over 250k questions asked about React and related libraries.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/02/React-in-Stackoverflow.PNG" alt="Image" width="600" height="400" loading="lazy">
<em>React on Stackoverflow</em></p>
<p>In some cases, you don't even need to create your components. There are lots of free and mature component libraries already available online. </p>
<p>Here are some examples:</p>
<ul>
<li>Microsoft has created the <a target="_blank" href="https://developer.microsoft.com/en-us/fluentui#/">Fluent UI</a> component library that gives you a chance to develop your UI (resembles <a target="_blank" href="https://www.office.com/">office</a>).</li>
<li><a target="_blank" href="https://material-ui.com/">Material-UI</a> offers React components that implement Google's Material UI guidelines.</li>
<li><a target="_blank" href="https://react-bootstrap.github.io/">React-Bootstrap</a> contains React components that make it easy to work with Bootstrap.</li>
<li>Also, check the <a target="_blank" href="https://github.com/brillout/awesome-react-components">Awesome React Components</a> list on GitHub to find more React components.</li>
</ul>
<p>There are also mature related projects/libraries that you can use with React. </p>
<ul>
<li>If you want routing, then go for <a target="_blank" href="https://reactrouter.com/">React Router</a>. If you want to manage a more complex data system, then use <a target="_blank" href="https://redux.js.org/">Redux</a> and <a target="_blank" href="https://mobx.js.org/README.html">MobX</a>.</li>
<li>For automated testing, use <a target="_blank" href="https://jestjs.io/">Jest</a>, which is also from Facebook. </li>
<li>For RESTful API calls, use <a target="_blank" href="https://graphql.org/">GraphQL</a>. </li>
<li>For the server-side rendering of React components with node, use <a target="_blank" href="https://expressjs.com/">Express.js</a>.</li>
</ul>
<p>All these libraries and tools are important, because if you are looking to build something in React, you will find tons of help and solutions on the web for everything.</p>
<h2 id="heading-react-has-great-performance">React Has Great Performance</h2>
<p>The React team realized that JavaScript is fast, but updating the DOM makes it slow. React minimizes DOM changes. And it has figured out the most efficient and intelligent way to update DOM.</p>
<p>Before React, most frameworks and libraries would update the DOM unintelligently to reflect a new state. This resulted in changes to a significant portion of the page.</p>
<p>React monitors the values of each component's state with the <a target="_blank" href="https://reactjs.org/docs/faq-internals.html">Virtual DOM</a>. When a component's state changes, React compares the existing DOM state with what the new DOM should look like. After that, it finds the least expensive way to update the DOM.</p>
<p>This doesn't seem very easy, but React handles it very well behind the scenes. It has multiple benefits like avoiding layout trashing, which is when the browser has to re-calculate the position of everything when the DOM element changes.</p>
<p>Also, since most applications are being used on mobile devices they need to be highly efficient. So, saving battery and CPU power is very important.</p>
<p>React's simple programming model allows it to change state automatically when data gets updated. This happens in the memory, so it is speedy.</p>
<p>React's library size is also tiny. It is less than <strong>6kb</strong> (less than 3kb when gzipped). This is significantly smaller than its competitors.</p>
<h2 id="heading-react-is-easy-to-test">React is Easy to Test</h2>
<p>React's design is very user friendly for testing. </p>
<ul>
<li>Traditional UI browser testing is a hassle to setup. On the other hand, you require very little or no configuration for testing in React.</li>
<li>Traditional UI browser requires browsers for testing, but you can test React components quickly and easily using the node command-line.</li>
<li>Traditional UI browser testing is slow. But command-line testing is fast, and you can run a considerable amount of test suites at a time.</li>
<li>Traditional UI browser testing is often time consuming and challenging to maintain. React test can be written quickly using tools like Jest &amp; <a target="_blank" href="https://enzymejs.github.io/enzyme/">Enzyme</a>.  </li>
</ul>
<p>There are wide variety of JavaScript testing frameworks available on the web that you can use to test React.js (since it's also a JavaScript library). Some popular testing frameworks are <a target="_blank" href="https://mochajs.org/">Mocha</a>, <a target="_blank" href="https://jasmine.github.io/">Jasmine</a>, <a target="_blank" href="https://github.com/substack/tape">Tape</a>, <a target="_blank" href="https://qunitjs.com/">QUnit</a>, and <a target="_blank" href="https://github.com/avajs/ava">AVA</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>React is an excellent tool with which to create interactive applications for mobile, web, and other platforms. </p>
<p>React's popularity and usage are increasing day by day for good reason. As a developer, coding in React makes you better at JavaScript, a language that holds nearly 90% of the web development share today.</p>
<p><em>Thank You for reading this article. Connect me on <a target="_blank" href="https://www.linkedin.com/in/suraj-surve/">LinkedIn</a>  and read more about Web Development on my <a target="_blank" href="https://www.tutorialfunda.com/">Blog</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Facades in Laravel ]]>
                </title>
                <description>
                    <![CDATA[ Facades are one of the key things you should understand when learning Laravel. It took me a considerable amount of time to figure out how facades work, and I'm writing this to help anyone who is having trouble wrapping their heads around the concept.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-facades-in-laravel/</link>
                <guid isPermaLink="false">66ba2fc3f1ac6be9964fe7a5</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Sule-Balogun Olanrewaju ]]>
                </dc:creator>
                <pubDate>Tue, 08 Dec 2020 19:32:33 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c95ff740569d1a4ca0f32.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Facades are one of the key things you should understand when learning Laravel.</p>
<p>It took me a considerable amount of time to figure out how facades work, and I'm writing this to help anyone who is having trouble wrapping their heads around the concept.</p>
<p>In this article we'll cover what facades are, how they're used in Laravel, how you can build your own simple facade, and more.</p>
<h2 id="heading-what-is-a-facade-and-what-is-a-wrapper">What is a facade? And what is a wrapper?</h2>
<p>A facade in Laravel is a wrapper around a non-static function that turns it into a static function.</p>
<p>The word "wrapper" can also be used when describing design patterns. Wrapping an object to provide a simplified interface to it is often described as the "facade" pattern. </p>
<p>So in short, the <a target="_blank" href="https://en.wikipedia.org/wiki/Wrapper_function">wrapper</a> is the facade.</p>
<p>Before diving deeper into facades, it's important to understand what static and non-static functions are in PHP.</p>
<h3 id="heading-static-methods">Static Methods</h3>
<p>In Static methods we're not required to create an instance of a class to reference it. Static methods use double colons (::) when accessing properties or methods of a class:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calc</span> </span>{
    <span class="hljs-keyword">const</span> GOLDEN_RATIO = <span class="hljs-string">'1.618'</span>;
}

<span class="hljs-keyword">echo</span> Calc::GOLDEN_RATIO;  <span class="hljs-comment">//1.618</span>
</code></pre>
<p>Reserved keywords like <code>self</code> , <code>static</code> and <code>parents</code> is used to reference properties or methods within a class:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">backend</span> </span>{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> language = <span class="hljs-string">"php"</span>;
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">language</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">echo</span> <span class="hljs-built_in">self</span>::language;
      }
}

backend::language();  <span class="hljs-comment">//php</span>
</code></pre>
<h3 id="heading-non-static-methods">Non-static Methods</h3>
<p>Non-static methods require that a given class be instantiated. In other words, they require an instance of the class to execute:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">backend</span></span>{

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">language</span>(<span class="hljs-params">$name</span>)</span>{

        <span class="hljs-keyword">echo</span> $name;
    }

}


$test = <span class="hljs-keyword">new</span> backend; <span class="hljs-comment">//creating an instance of the class</span>

$test-&gt;language(<span class="hljs-string">'php'</span>); <span class="hljs-comment">//php</span>
</code></pre>
<p>Now that we've gone over static and non-static methods, we can dive deeper into facades in Laravel.</p>
<h2 id="heading-laravel-facades">Laravel facades</h2>
<p>In the <code>vendors &gt; laravel  &gt; framework &gt; src &gt; illuminate &gt; support &gt; Facades</code> directory, there's a list of files which are the various facades that ship with Laravel by default.</p>
<p>Here's a screenshot of what the directory structure actually looks like in our editor:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/11/Screenshot-2020-11-26-at-01.06.09.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's use the working code from <code>Log.php</code> to examine facades in more detail – the same explanation should apply to all facades in any Laravel application.</p>
<h3 id="heading-laravels-log-facade">Laravel's Log facade</h3>
<p>Here's the code for Laravel's <code>Log</code> facade:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Log</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span>
</span>{
    <span class="hljs-comment">/**
     * Get the registered name of the component.
     *
     * <span class="hljs-doctag">@return</span> string
     */</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'log'</span>;
    }
}
</code></pre>
<p><code>Log</code> is a class that extends the base facade which is from the namespace above.</p>
<p>Within the <code>Log</code> class we have a protected access modifier, <code>getFacadeAccessor</code>, and what that method does is it just returns <code>log</code>. </p>
<p>The name of this facade, <code>log</code>, is being returned so we can access the named facade anywhere within the Laravel application without initializing it. So we can do something like <code>Log::info('hello there');</code> anywhere really easily.</p>
<p>As you can see, facades make code easier to read, more organized, and make testing 10 times easier.</p>
<p>Since learning about <code>Log</code> from one of my co-workers, it's been my favorite debugging tool.</p>
<h2 id="heading-how-to-create-a-facade-in-laravel">How to create a facade in Laravel</h2>
<p>In this section we'll implement our own facade. The main objective here is to help learners understand how Laravel facades work.</p>
<p>We'll do this by creating a StudentFacade which will extend properties from a base Facade that returns a name property after it has been resolved. This name property will be of type string and it will be returned each time we instantiate the class as shown below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/Screenshot-2020-12-05-at-21.13.39.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Curious how we will achieve this? Follow along as I'll be walking you through the steps.</p>
<p>We won't be creating our facade using the normal Laravel convention where we have a <code>.php file</code> in <code>app &gt; facade</code> and then another in the <code>providers</code> before we end up registering it in the <code>config &gt; app</code>. </p>
<p>Instead, we will make do with the <code>web.php</code> inside the <code>routes</code> for this illustration since we're just trying to see how facades work under the hood in a typical Laravel application.</p>
<p>First, let's start with this in <code>web.php</code>:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span> 
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">students</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Sean'</span>;
    }
}

 app()-&gt;bind(<span class="hljs-string">'student'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
     <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Student;   
 });
</code></pre>
<p>We've created a class <code>Student</code>, and inside it we have a non-static <code>students</code> method that returns an array of students.</p>
<p>Then we call the <em>bind</em> method to make it always instantiate <code>new Student</code> so we don't need to do this manually anymore.</p>
<p>Next, let's create a base <code>Facade</code> class still within the same <code>web.php</code>:</p>
<pre><code class="lang-php"> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Facade</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__callStatic</span>(<span class="hljs-params">$name, $args</span>)</span>{
        <span class="hljs-keyword">return</span> app()-&gt;make(<span class="hljs-built_in">static</span>::getFacadeAccessor())-&gt;$name();
    }

    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">//override take place </span>
    }
}
</code></pre>
<p>Any facade we might create later will be extending the properties of this base facade.</p>
<p>Within the <code>Facade</code> class we have a <code>__callStatic</code> <a target="_blank" href="https://www.php.net/manual/en/language.oop5.magic.php">magic method</a> that helps us resolve the <code>static::getFacadeAccessor()</code> from the container with <code>app()-&gt;make()</code>. And with those we're able to access the <code>$name</code> property.</p>
<pre><code class="lang-php"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentFacade</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span> </span>{
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'student'</span>;
    }
}
</code></pre>
<p>Here, <code>StudentFacade</code> inherits the properties of the base facade. Then we override <code>getFacadeAccessor()</code> and set the return value to be whatever we have each time we instantiate in the bind above <code>student</code>.</p>
<pre><code class="lang-php">StudentFacade::students(); <span class="hljs-comment">//output "Sean"</span>
</code></pre>
<p>When we try to call the facade which we created it returns "Sean" as expected. Now in the final step we have to put all these steps together:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">students</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'Sean'</span>;
    }
}

 app()-&gt;bind(<span class="hljs-string">'student'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Student;   
 }); 


 <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Facade</span></span>{
    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__callStatic</span>(<span class="hljs-params">$name, $args</span>)</span>{
        <span class="hljs-keyword">return</span> app()-&gt;make(<span class="hljs-built_in">static</span>::getFacadeAccessor())-&gt;$name();
    }

    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">//override take place </span>
    }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentFacade</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Facade</span> </span>{
    <span class="hljs-keyword">protected</span> <span class="hljs-built_in">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFacadeAccessor</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">'student'</span>;
    }
}

<span class="hljs-comment">//log or die it to the output</span>
dd(StudentFacade::students());
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/12/Screenshot-2020-12-05-at-21.13.39-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope that by the end of this lesson you have been able to broaden your knowledge about facades work. If you have questions or wish to continue the conversation feel free to tweet at me.</p>
<h3 id="heading-references">References</h3>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zD2VJhOdI5c">Laravel Beginner tutorial</a> - Bitfumes</p>
<p><a target="_blank" href="https://stackoverflow.com/questions/3293752/where-and-how-is-the-term-used-wrapper-in-programming-what-does-it-help-to-do">What is WRAPPER in programming, what does it help to do?</a> - Stackoverflow</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ AWS Machine Learning Tools: The Complete Guide ]]>
                </title>
                <description>
                    <![CDATA[ In this article, we will take a look the machine learning tools offered by AWS. We'll also understand the type of problems they try to solve for their customers. AWS Machine Learning comprises a rich set of tools that Amazon offers to help developers... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/aws-machine-learning-tools-the-complete-guide/</link>
                <guid isPermaLink="false">66d035b2871ae63f179f6b8f</guid>
                
                    <category>
                        <![CDATA[ Artificial Intelligence ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tools ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Manish Shivanandhan ]]>
                </dc:creator>
                <pubDate>Tue, 06 Oct 2020 12:10:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/09/wall-7.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this article, we will take a look the machine learning tools offered by AWS. We'll also understand the type of problems they try to solve for their customers.</p>
<p><a target="_blank" href="https://aws.amazon.com/machine-learning/">AWS Machine Learning</a> comprises a rich set of tools that Amazon offers to help developers integrate machine learning models into their applications. </p>
<p>AWS also offers pre-trained models for use cases including computer vision, recommendation engines, and language translation.</p>
<p>Amazon currently offers 15 machine learning services on its platform. In this article, we will take a look at each one of them so we can understand the type of problem they are trying to solve for their customers.</p>
<h2 id="heading-sagemaker">SageMaker</h2>
<p><a target="_blank" href="https://aws.amazon.com/sagemaker/">Amazon SageMaker</a> helps you to take your machine learning models from concept to production in a fraction of time compared to traditional code-based approaches. </p>
<p>Sagemaker is a managed service and has the complete suite of tools you need to build, train, and deploy your machine learning models. They help you label your data, optimize your algorithms, and more. It's a complete solution for creating and deploying machine learning models.</p>
<p>SageMaker also has an autopilot option that will automatically process the data and run it through multiple algorithms. This helps developers find the best algorithm for their model without manually training and testing those models. </p>
<p>Sagemaker also comes with an integrated IDE and a sharable Jupyter notebook that you can use to collaborate with your team.</p>
<h2 id="heading-codeguru">CodeGuru</h2>
<p><a target="_blank" href="https://aws.amazon.com/codeguru/">Amazon CodeGuru</a> lets you automate your code reviews and performance optimizations for your application. </p>
<p>It can find issues like <a target="_blank" href="https://searchstorage.techtarget.com/definition/race-condition">race conditions</a>, resource leaks, and wasted CPU cycles. This helps you produce higher quality code by providing specific recommendations based on code context.</p>
<p>Codeguru’s algorithms are trained with codebases from Amazon’s projects. Right now, CodeGuru supports only Java applications, but you can expect the functionality to extend to other languages in the near future.</p>
<h2 id="heading-comprehend">Comprehend</h2>
<p><a target="_blank" href="https://aws.amazon.com/comprehend/">Amazon Comprehend</a> is a Natural Language Processing service from Amazon that uses machine learning to find valuable insights from textual data. </p>
<p>Comprehend can work with unstructured data like product reviews, customer emails, twitter tweets, and so on to help you draw conclusions (like overall audience sentiment).</p>
<p>It's also a fully managed service, meaning you can use pre-trained models to work with your data. Comprehend also has an additional service called Amazon Comprehend Medical that lets you work with medical documents to analyze medical conditions and dosages.</p>
<h2 id="heading-forecast">Forecast</h2>
<p><a target="_blank" href="https://aws.amazon.com/forecast/">Amazon Forecast</a> is used to build time-series prediction models using your existing datasets. </p>
<p>Forecast works great for use cases like predicting future business expenses, stock price prediction, and resource planning for organizations based on customer demand.</p>
<p>This service is also customizable and lets you build custom models on top of Amazon’s existing deep learning models. Like most machine learning tools in AWS, Forecast is also fully managed and can scale according to your business needs.</p>
<h2 id="heading-fraud-detector">Fraud Detector</h2>
<p><a target="_blank" href="https://aws.amazon.com/fraud-detector/">Amazon Fraud Detector</a> is another fully managed service that helps you detect fake registrations and fraudulent transactions. </p>
<p>Fraud detector can identify potentially fraudulent accounts and then helps you set up additional verification for those flagged accounts.</p>
<p>A fraud detector needs an existing dataset of labeled fraudulent transactions in order to train and understand the pattern of your customer behavior. It then uses this data to prevent further fraudulent transactions. </p>
<p>You can also configure custom authentication rules for guest logins and product trials.</p>
<h2 id="heading-kendra">Kendra</h2>
<p><a target="_blank" href="https://aws.amazon.com/kendra/">Amazon Kendra</a> is an AI-powered enterprise search engine that will help you deliver highly accurate search results based on customer queries. </p>
<p>You can use. Kendra to power search engines in your products that help your users find exactly what they're looking for.</p>
<p>Kendra can also be used to help customers find answers to specific problems while using your product without the need for additional customer support. </p>
<p>Kendra also supports natural language questions, delivering an even smoother experience for your customers.</p>
<h2 id="heading-lex">Lex</h2>
<p><a target="_blank" href="https://aws.amazon.com/lex/">Amazon Lex</a> lets you build conversational interfaces into your products. Lex offers <a target="_blank" href="https://en.wikipedia.org/wiki/Natural-language_understanding">Natural Language Understanding (NLU)</a> models that can understand conversational input from users and perform the right actions.</p>
<p>Lex can be used as a replacement for manual customer support to help filter common queries, and it can answer them automatically. It is also a fully managed service that scales automatically and uses a pay-as-you-use model.</p>
<h2 id="heading-personalize">Personalize</h2>
<p><a target="_blank" href="https://aws.amazon.com/personalize/">Amazon Personalize</a> lets you create custom recommendations for your customers based on their usage patterns. </p>
<p>While traditional recommendation engines can be used only to recommend products, Personalize lets you literally personalize every step of your customer’s user experience.</p>
<p>Personalize is a great tool to build product recommendations, custom search results based on queries and employ targeted marketing promotions.</p>
<h2 id="heading-polly">Polly</h2>
<p><a target="_blank" href="https://aws.amazon.com/polly/">Amazon Polly</a> helps you build speech-enabled products for your customers. Polly provides lifelike voice outputs across a variety of languages including Chinese, Korean and Japanese.</p>
<p>Polly is powered by deep learning algorithms that mimic a conversational style interface that can be used in narrations, telephony applications, and other applications.</p>
<h2 id="heading-rekognition">Rekognition</h2>
<p><a target="_blank" href="https://aws.amazon.com/rekognition/">Amazon Rekognition</a> is a computer vision solution from AWS that helps developers build applications that can recognize objects from images and videos. </p>
<p>In addition to automatic object recognition, you can customize Rekognition to pick out specific objects and scenes based on your own requirements.</p>
<p>Rekognition can be used in use cases like identifying manufacturing defects in products, spotting unauthorized personnel in an organization, scanning for inappropriate content in movies, and so on. It can also be used to analyze player movements in games for post-game analysis.</p>
<h2 id="heading-textract">Textract</h2>
<p><a target="_blank" href="https://aws.amazon.com/textract/">Amazon Textract</a> enables you to read data from scanned documents. The usual approach to digitizing paper documents is using manual data entry or <a target="_blank" href="https://en.wikipedia.org/wiki/Optical_character_recognition">OCRs</a> with custom configurations. </p>
<p>Textract makes it easier by automatically applying rules to documents and extracting valuable data along with components like forms and images within the document.</p>
<p>Textract is useful for processing loan applications, medical claims, and more. In addition to extracting data, these can be optimized for search using Textract. Documents that usually take months to process using manual methods can be processed in hours using AWS Textract.</p>
<h2 id="heading-transcribe">Transcribe</h2>
<p><a target="_blank" href="https://aws.amazon.com/transcribe/">Amazon Transcribe</a> lets you build speech to text services in your application. Transcribe is useful in building medical transcription services, streaming audio, generating subtitles for video recordings, and more.</p>
<p>Transcribe can also be used to convert customer calls into text and analyze them for improved customer service. Cataloging audio archives is another use case for AWS transcribe.</p>
<h2 id="heading-translate">Translate</h2>
<p><a target="_blank" href="https://aws.amazon.com/translate/">Amazon Translate</a> is a machine learning service similar to Google Translate. Translate can work with a variety of languages with high accuracy, which lets businesses customize their languages based on the the demographics of their audiences.</p>
<p>Translate is also designed to be more natural-sounding to customers since the context of the sentence is also taken into account. </p>
<p>Translate is also highly customizable so it can help improve the accuracy of translation when working with your brand names and unique words related to your business.</p>
<h2 id="heading-deeplens">DeepLens</h2>
<p><a target="_blank" href="https://aws.amazon.com/deeplens/">Amazon DeepLens</a> is a video camera with in-built deep learning capabilities that helps you build and test computer vision models in real-time. </p>
<p>DeepLens is fully programmable and can be used to test models like live object recognition, classifying birds/ animals, face detection, and so on.</p>
<p>The product is designed for developers getting started in machine learning. It helps them get a grasp of how their models will work in the real world. </p>
<p>DeepLens is also integrated with the AWS ecosystem and can be used with other AWS services like Lambda and Rekognition to extend its capabilities.</p>
<h2 id="heading-deepracer">DeepRacer</h2>
<p>If you are a fan of self-driving cars, <a target="_blank" href="https://aws.amazon.com/deepracer/">AWS DeepRacer</a> is a small autonomous race car designed by AWS that runs using machine learning. DeepRacer helps you test your reinforcement learning models using a physical track.</p>
<p>You can build reinforcement learning models using AWS SageMaker and test them instantly using DeepRacer. Amazon also gives you the opportunity to connect and compete with fellow racing enthusiasts by building virtual private race tracks.</p>
<h2 id="heading-summary">Summary</h2>
<p>With a solution to almost every machine learning problem, Amazon Machine Learning offers a rich set of tools for machine learning engineers to work with. </p>
<p>Amazon also adds new services every few months based on new use cases, making it one of the most dependable platforms where engineers can build AI solutions for their customers.</p>
<p><em>Loved this article?</em> <a target="_blank" href="http://tinyletter.com/manishmshiva"><strong><em>Join my Newsletter</em></strong></a> <em>and get a summary of my articles and videos every Monday.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Storybook and How Can I Use It to Create a Component Library in React? ]]>
                </title>
                <description>
                    <![CDATA[ Frameworks like React, Vue, and Angular all help developers create modular systems using components, but that doesn't usually include a good way to see them all from a higher point of view.  So how can we use Storybook to build libraries and design s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-storybook-and-how-can-i-use-it-to-create-a-component-libary-in-react/</link>
                <guid isPermaLink="false">66b8e39c68c5b9f37d1d1af1</guid>
                
                    <category>
                        <![CDATA[ components ]]>
                    </category>
                
                    <category>
                        <![CDATA[ create-react-app ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design Tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer Tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Libraries ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Storybook ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tools ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Tue, 09 Jun 2020 14:45:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/storybook.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Frameworks like React, Vue, and Angular all help developers create modular systems using components, but that doesn't usually include a good way to see them all from a higher point of view. </p>
<p>So how can we use Storybook to build libraries and design systems that self-document as we build them?</p>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-storybook">What is Storybook?</a></li>
<li><a class="post-section-overview" href="#heading-what-are-we-going-to-build">What are we going to build?</a></li>
<li><a class="post-section-overview" href="#heading-step-0-bootstrapping-an-app">Step 0: Bootstrapping an app</a></li>
<li><a class="post-section-overview" href="#heading-step-1-installing-storybook">Step 1: Installing Storybook</a></li>
<li><a class="post-section-overview" href="#heading-step-2-creating-a-new-button">Step 2: Creating a new button</a></li>
<li><a class="post-section-overview" href="#heading-step-3-using-our-new-button-component">Step 3: Using our new Button component</a></li>
<li><a class="post-section-overview" href="#heading-repeat-creating-a-new-header-component">Repeat: Creating a new Header component</a></li>
<li><a class="post-section-overview" href="#heading-more-storybook-features">More Storybook features</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/VApXDsYO5Gg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-what-is-storybook">What is Storybook?</h2>
<p><a target="_blank" href="https://storybook.js.org/">Storybook</a> is a JavaScript tool that allows developers to create organized UI systems making both the building process and documentation more efficient and easier to use.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/loneley-planet-storybook-example.jpg" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://lonelyplanet.github.io/backpack-ui/?path=/story/cards--card-basic">Lonely Planet's Backpack UI</a></em></p>
<p>Once you build out a component, Storybook lets you create a "story" file where you can then import your component and create various use case examples in an iFramed sandbox using that component.</p>
<p>This provides an organized and focused environment to build new components and work on existing ones.</p>
<h2 id="heading-what-are-we-going-to-build">What are we going to build?</h2>
<p>We're going to bootstrap a new <a target="_blank" href="https://reactjs.org/">React JS</a> app using <a target="_blank" href="https://reactjs.org/docs/create-a-new-react-app.html">Create React App</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-component-example.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Inside that app, we're going to install Storybook and create a few new components that will help us learn how to create new components that we can work on in a story and then use it in a React app.</p>
<h2 id="heading-step-0-bootstrapping-an-app">Step 0: Bootstrapping an app</h2>
<p>To get started, we're going to start from scratch with <a target="_blank" href="https://reactjs.org/docs/create-a-new-react-app.html">Create React App</a>. This will help us focus on getting productive in Storybook rather than walking through integrating it into a current app.</p>
<p>That said, if you're already working with an app created using Create React App that's not ejected, you should be able to still follow on with Part 1 and beyond just the same!</p>
<p>So let's get started by navigating to where we want to create our new app and run the Create React App command:</p>
<pre><code class="lang-shell">npx create-react-app my-storybook
</code></pre>
<p><em>Note: feel free to replace <code>my-storybook</code> with the directory name of your choice.</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/create-new-react-app.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Bootstrapping with Create React App</em></p>
<p>Once that's finished running, you can navigate to the directory:</p>
<pre><code class="lang-shell">cd my-storybook
</code></pre>
<p>And we're ready to go!</p>
<h2 id="heading-step-1-installing-storybook">Step 1: Installing Storybook</h2>
<p>Storybook luckily makes it really easy to get started with a standard installation of React. Particularly with Create React App, Storybook automatically detects that we're using an app created using CRA and installs the dependencies and scaffolds everything for us.</p>
<h3 id="heading-initializing-storybook">Initializing Storybook</h3>
<p>To get started installing Storybook, run:</p>
<pre><code class="lang-shell">npx -p @storybook/cli sb init
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/initializing-storybook.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Initializing Storybook in a React app</em></p>
<p>If you aren't using Create React App or it didn't work, you can check out their <a target="_blank" href="https://storybook.js.org/docs/guides/guide-react/">available guides in their docs</a>.</p>
<p>After that's finished, all of our Storybook dependencies should be installed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-finished-installing.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Finished installing Storybook</em></p>
<h3 id="heading-starting-up-storybook">Starting up Storybook</h3>
<p>So now we're ready to get moving! Finally, run:</p>
<pre><code class="lang-shell">yarn storybook
# or
npm run storybook
</code></pre>
<p>And once everything finishes loading, Storybook will open a new tab in your browser and you should now see a welcome message inside of your new Storybook dashboard!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-welcome-page.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Storybook welcome page</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-storybook/commit/3e994096384e31cb540150c9f14f41758ef3a746">Follow along with the commit!</a></p>
<h2 id="heading-step-2-creating-a-new-button">Step 2: Creating a new button</h2>
<p>If you took a second to poke around the dashboard, you might have noticed that it comes pre-loaded with a Button that's available as a demo.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-demo-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Storybook demo button</em></p>
<p>You should also notice if you click the button, you actually see an action print out inside of the Actions tab at the bottom. This shows the event that's captured from the button click.</p>
<p>It's simple, but this is great to get a nice feel about what to expect in storybook. The only issue is, this is meant purely for demonstration purposes, so let's build our own button to replace it.</p>
<h3 id="heading-creating-a-new-button-component">Creating a new Button component</h3>
<p>To get started, let's first create a few directories:</p>
<ul>
<li>Under <code>src</code>, create a new folder called <code>components</code></li>
<li>Under <code>components</code>, create a new folder called <code>Button</code></li>
</ul>
<p>Once you create those folders, create a new file called <code>index.js</code> inside of your <code>src/components/Button</code> folder and inside add:</p>
<pre><code class="lang-js"><span class="hljs-comment">// Inside src/components/Button/index.js</span>

<span class="hljs-keyword">export</span> { <span class="hljs-keyword">default</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'./Button'</span>;
</code></pre>
<p>This will import the next file we created called <code>Button.js</code> which will allow us to more easily import our files with <code>src/components/Button</code> instead of <code>/src/components/Button/Button</code>.</p>
<p>Next, let's create <code>Button.js</code> right next to our <code>index.js</code> file with the following content:</p>
<pre><code class="lang-js"><span class="hljs-comment">// Inside src/components/Button/Button.js</span>

<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">const</span> Button = <span class="hljs-function">(<span class="hljs-params">{ children, ...rest }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"button"</span> {<span class="hljs-attr">...rest</span>}&gt;</span>
      { children }
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Button;
</code></pre>
<p>Here, we're creating a new component called Button that adds a class of <code>button</code> to the element and passes through the <code>children</code>. We're a additionally <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment">destructuring</a> the rest of the props into the <code>rest</code> variable and <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax">spreading</a> that value into the <code>&lt;button&gt;</code> element.</p>
<p>If you've followed along, your files should now look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/button-reaect-component.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Button component in React</em></p>
<h3 id="heading-using-our-new-button-component">Using our new Button component</h3>
<p>So now that we have our Button component, let's use it!</p>
<p>Open up the file <code>src/stories/1-Button.stories.js</code> and replace the line that's importing <code>Button</code> with:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/updating-button-storybook-story.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Updating the Button Storybook story</em></p>
<p>And once you hit save, you can open back up your browser tab with your Storybook dashboard, and you can now see a button that looks mostly similar, but it uses the browser's default styles for the <code>&lt;button&gt;</code> element. You'll even notice that if you click it, the event will still be logged under the Actions tab.</p>
<h3 id="heading-styling-our-button-component">Styling our Button component</h3>
<p>Finally, we probably don't want to use the browser default styles, so let's make it look nice.</p>
<p>In our <code>src/components/Button</code> directory, add a new file <code>Button.css</code> and add the following content:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Inside src/components/Button/Button.css */</span>

<span class="hljs-selector-class">.button</span> {
  <span class="hljs-attribute">color</span>: white;
  <span class="hljs-attribute">font-weight</span>: bold;
  <span class="hljs-attribute">background-color</span>: blueviolet;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">padding</span>: .<span class="hljs-number">8em</span> <span class="hljs-number">1em</span>;
  <span class="hljs-attribute">border-radius</span>: .<span class="hljs-number">2rem</span>;
}
</code></pre>
<p>This applies a few styles to our <code>.button</code> class like adding a background color and changing the font color to white.</p>
<p>But if you open Storybook, you'll notice it didn't do anything. To use it, we need to import it into our component.</p>
<p>Inside <code>src/components/Button/Button.js</code> add the following at the top under the React import:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> <span class="hljs-string">'./Button.css'</span>;
</code></pre>
<p>And once you save that and open up your browser, you should now see our new button with our updated styles!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/new-button-storybook.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Button in Storybook</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-storybook/commit/e71e0e9e666adee0455b0b69118053c2f551ab68">Follow along with the commit!</a></p>
<h2 id="heading-step-3-using-our-new-button-component">Step 3: Using our new Button component</h2>
<p>The ultimate goal of our component is to use it right? So let's add it to our app.</p>
<h3 id="heading-switching-over-to-the-react-app">Switching over to the React app</h3>
<p>First we'll need to either start our React app in a new terminal tab or kill the Storybook process and start the React process there. To start the React app using Create React App, run:</p>
<pre><code class="lang-shell">yarn start
# or
npm run start
</code></pre>
<p>Once that loads, we should have our standard Create React App if you're following along with me:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/new-create-react-app.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Create React App</em></p>
<h3 id="heading-importing-and-using-the-new-button">Importing and using the new button</h3>
<p>Next, inside of <code>src/App.js</code>, let's import our new Button at the top of the page:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> Button <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Button'</span>;
</code></pre>
<p>With Button imported, we can use it. Here, we can simply add it anywhere we want in the page. I'm going to replace the Learn React link with:</p>
<pre><code class="lang-jsx">&lt;p&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Button</span>&gt;</span>Hello, Storybook!<span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span></span>
&lt;/p&gt;
</code></pre>
<p>And if we save and reload the page, we should now see our Button on the page!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/create-react-app-with-new-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Button in Create React App</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-storybook/commit/e6071aae5be281101d486c4cc7664bf6cacb4028">Follow along with the commit</a></p>
<h2 id="heading-repeat-creating-a-new-header-component">Repeat: Creating a new Header component</h2>
<p>The great thing about Storybook and React (or any of the supported frameworks) is that this process scales to as many components as you want.</p>
<p>So let's build another component!</p>
<h3 id="heading-creating-our-header-component">Creating our Header component</h3>
<p>Similar to our Button, let's start off by creating the set of directories and files that give us our component.</p>
<p>Since we already did this once, I'm going to provide the code without walking through what's going on.</p>
<p>Let's start off by spinning back up our Storybook server with:</p>
<pre><code>yarn storybook
# or 
npm run storybook
</code></pre><p>Create a <code>Header</code> directory inside the <code>src/components</code> directory.</p>
<p>Create an <code>index.js</code> file inside of <code>src/components/Header</code> with the following content:</p>
<pre><code class="lang-js"><span class="hljs-comment">// In src/components/Header/index.js</span>

<span class="hljs-keyword">export</span> { <span class="hljs-keyword">default</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'./Header'</span>;
</code></pre>
<p>Create a <code>Header.js</code> file inside of <code>src/components/Header</code> with the following content:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// In src/components/Header/Header.js</span>

<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'./Header.css'</span>;

<span class="hljs-keyword">const</span> Header = <span class="hljs-function">(<span class="hljs-params">{ children }</span>) =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"header"</span>&gt;</span>
      { children }
    <span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>
  )
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> Header;
</code></pre>
<p>Create a <code>Header.css</code> file inside of <code>src/components/Header</code> with the following content:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* In src/components/Header/Header.css */</span>

<span class="hljs-selector-class">.header</span> {
  <span class="hljs-attribute">font-family</span>: sans-serif;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2.5em</span>;
  <span class="hljs-attribute">color</span>: blueviolet;
  <span class="hljs-attribute">border-bottom</span>: solid <span class="hljs-number">5px</span> aqua;
  <span class="hljs-attribute">padding-bottom</span>: .<span class="hljs-number">2em</span>;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">5px</span> <span class="hljs-number">0</span> blueviolet;
}
</code></pre>
<p>Now if you notice, if you try to open up Storybook, again, nothing will happen. This time we need to create a new story file.</p>
<h3 id="heading-creating-a-new-story-file">Creating a new Story file</h3>
<p>Inside <code>src/stories</code>, add a new file called <code>2-Header.stories.js</code>:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// Inside src/stories/2-Header.stories.js</span>

<span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">import</span> Header <span class="hljs-keyword">from</span> <span class="hljs-string">'../components/Header'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-attr">title</span>: <span class="hljs-string">'Header'</span>,
  <span class="hljs-attr">component</span>: Header,
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> Text = <span class="hljs-function">() =&gt;</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Header</span>&gt;</span>Hello Header<span class="hljs-tag">&lt;/<span class="hljs-name">Header</span>&gt;</span></span>;
</code></pre>
<p>Here's a breakdown of our story file:</p>
<ul>
<li>First, we import our component – this is pretty standard any time we want to use it</li>
<li>The first thing we export is a <code>default</code> object. With Storybook, it expects the default export to be the configuration of our story, so here we provide it with a title and we pass in the component that we're using for this story</li>
<li>The second and last thing we export is the <code>Text</code> constant. With Storybook, any non-default export will be considered a variation that will get nested under the title that you provide in the default export</li>
</ul>
<p>And if you save this file and open up your Storybook dashboard in the browser, you should now see the new header!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/new-header-storybook-story.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Header component in Storybook</em></p>
<h3 id="heading-using-the-header-component">Using the Header component</h3>
<p>Using our component is just the same as our Button component, so inside of <code>src/App.js</code>, let's add our Header.</p>
<p>After starting your React server, first import our new Header:</p>
<pre><code class="lang-js"><span class="hljs-comment">// In src/App.js</span>

<span class="hljs-keyword">import</span> Header <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/Header'</span>;
</code></pre>
<p>Then add it to the top of the page:</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// In src/App.js</span>

&lt;Header&gt;My App&lt;/Header&gt;
</code></pre>
<p>And if you open the page, we'll see our new Header!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/create-react-app-with-header-and-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Create React App with new Header and Button components</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-storybook/commit/e1c59eccaf5f4146a2fe039dca8874609d615194">Follow along with the commit!</a></p>
<h2 id="heading-adding-more-components">Adding more components</h2>
<p>As you've noticed with our second Repeat step – adding a new component is pretty much the same process for any type of component we want to add. Once we have it in our library, we can develop it in a focused environment and then import it to our app to use.</p>
<p>You can now use this to manage your library of components and better maintain an entire system for your project!</p>
<h2 id="heading-more-storybook-features">More Storybook features</h2>
<p>Storybook doesn't stop with just adding components, it provides the ability to configure <a target="_blank" href="https://storybook.js.org/addons/">Addons</a> that enhance the core capabilities opening up a lot of possibilities.</p>
<p>Here are some of my favorites...</p>
<h3 id="heading-story-source">Story Source</h3>
<p>When building a component system, the hope is that people can easily use these components. But if you don't have documentation, someone would have to open up the file or try to find another use example.</p>
<p>Instead, <a target="_blank" href="https://github.com/storybookjs/storybook/tree/master/addons/storysource">Story Source</a> shows the code source of the story file you created allowing someone browsing your Storybook dashboard to get an example right along with the component output!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-source-demo.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Storybook Story Source demo</em></p>
<h3 id="heading-storyshots">Storyshots</h3>
<p>If you're a fan of automated testing, you might have heard of using <a target="_blank" href="https://jestjs.io/">Jest</a> or another tool for adding snapshot testing to your app.</p>
<p><a target="_blank" href="https://github.com/storybookjs/storybook/tree/master/addons/storyshots/storyshots-core">StoryShots</a> is a way to easily add Jest snapshot testing to your component system. It creates snapshots based off of the stories you create so you can make sure that your components aren't fundamentally changing (or breaking) during development.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/06/storybook-snapshot-example.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Snapshot example with StoryShots</em></p>
<h2 id="heading-whats-your-favorite-part-of-storybook">What's your favorite part of Storybook?</h2>
<p><a target="_blank" href="https://twitter.com/colbyfayock">Share with me on Twitter!</a></p>
<h2 id="heading-continue-the-conversation">Continue the conversation!</h2>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/colbyfayock/status/1270392710260719616"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Svelte in 5 Minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Leanne Rybintsev This article gives you a lightning-speed overview of Svelte - a Javascript framework which lets you write less code, use no virtual DOM, and create truly reactive apps.  As if that's not enough, Svelte is super-intuitive too! Buil... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-svelte-in-5-minutes/</link>
                <guid isPermaLink="false">66d460143a8352b6c5a2aaa2</guid>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Svelte ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 08 Jun 2020 20:49:08 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/06/Screenshot-2020-06-06-at-16.10.39.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leanne Rybintsev</p>
<p>This article gives you a lightning-speed overview of Svelte - a Javascript framework which lets you write less code, use no virtual DOM, and create truly reactive apps. </p>
<p>As if that's not enough, Svelte is super-intuitive too! Built with developers in mind, it is designed to make coding easier, bug-squashing quicker, and a developer's work life generally happier. </p>
<p>If that sounds right up your street, then read on!</p>
<p>While 5 minutes won't be enough to teach you Svelte in depth, it does allow for a solid overview of the basics, including:</p>
<ul>
<li>Components</li>
<li>Importing and Exporting</li>
<li>Templating</li>
<li>Event handling</li>
<li>Event dispatching</li>
<li>Reactivity</li>
</ul>
<p>If you want to find out more about Svelte after reading this article, check out <a target="_blank" href="https://scrimba.com/course/glearnsvelte?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">the full course</a> over on Scrimba. There, you'll learn about even more Svelte features and have the chance to road test your new skills with a bunch of interactive challenges. </p>
<p>For now, let's get started on the basics!</p>
<h2 id="heading-components">Components</h2>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cNDg9yHB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/e8ej7929dpa3u9tzsm0u.png" alt="DOM displaying Svelte component" width="339" height="254" loading="lazy"></a>
<em>(Click the image to access the course.)</em></p>
<p>First, we'll take a look at how to build a Svelte component, which can contain three parts; <code>&lt;script&gt;</code>, which contains Javascript, <code>&lt;style&gt;</code>, which contains CSS and the HTML, which uses the JS from the <code>&lt;script&gt;</code> tag. </p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">let</span> say = <span class="hljs-string">'hi'</span>;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
    <span class="hljs-selector-tag">div</span> {
        <span class="hljs-attribute">color</span>: red;
    }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span></span>

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    Say: {say}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<p><strong>Note:</strong> The bare minimum needed for a Svelte component is the HTML, so the app will still work without the <code>&lt;script&gt;</code> and <code>&lt;style&gt;</code> tags.</p>
<h2 id="heading-importing-and-exporting">Importing and Exporting</h2>
<p>One big benefit of using frameworks is the ability to modularise code by splitting it into separate components. Components are then imported into the main app using <code>import</code> keyword: </p>
<pre><code class="lang-js">  <span class="hljs-keyword">import</span> Face <span class="hljs-keyword">from</span> <span class="hljs-string">'./Face.svelte'</span>;
</code></pre>
<p>Unlike with other frameworks, the <code>export</code> keyword is not required to use a component elsewhere in an app. Instead, it is used to pass parameters, or props, from parent elements to their children. </p>
<p>For example, we can set a size prop with a default size in our component:</p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">export</span> <span class="hljs-keyword">let</span> size = <span class="hljs-number">1</span>;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-size: {size}em"</span>&gt;</span>=)<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<p>This allows us to easily adjust the size of the imported component over in our <code>App.svelte</code> file: </p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">import</span> Face <span class="hljs-keyword">from</span> <span class="hljs-string">'./Face.svelte'</span>;
&lt;/script&gt;

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> <span class="hljs-attr">size</span>=<span class="hljs-string">"4"</span> /&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> <span class="hljs-attr">size</span>=<span class="hljs-string">"10"</span> /&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Face</span> /&gt;</span></span>
</code></pre>
<p>The various sizes appear on the DOM as follows:</p>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cbDNVncg?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/3aecnw1qq3xpcck19agr.png" alt="component imported with various sizes using props" width="368" height="431" loading="lazy"></a>
<em>(Click the image to access the course.)</em></p>
<p>Head over to <a target="_blank" href="https://scrimba.com/p/pG6X6UG/cbDNVncg?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">the course on Scrimba</a> to view and play around with the full code. </p>
<h2 id="heading-templating">Templating</h2>
<p>The Svelte <a target="_blank" href="https://scrimba.com/p/pG6X6UG/cMZrQds2?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">templating syntax</a> is a great feature which lets us add if statements and for loops to our HTML.</p>
<p>The syntax for an if statement looks like this:</p>
<pre><code class="lang-js">&lt;Container&gt;
    {#<span class="hljs-keyword">if</span> say}
        &lt;div&gt;
            Hi!
        &lt;/div&gt;

    {/<span class="hljs-keyword">if</span>}
&lt;/Container&gt;
</code></pre>
<p>While a for loop is as follows:</p>
<pre><code class="lang-js">{#each [<span class="hljs-number">2</span>,<span class="hljs-number">1</span>,<span class="hljs-number">0</span>] <span class="hljs-keyword">as</span> faceIndex}
        &lt;Face index={faceIndex} /&gt;
    {/each}
</code></pre>
<h2 id="heading-event-handling">Event handling</h2>
<p>To allow the user to interact with our app, we need event handlers. In <a target="_blank" href="https://scrimba.com/p/pG6X6UG/caZ3J6U3?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">this scrim</a>, we see how to add a simple <code>on:click</code> to a <code>&lt;button&gt;</code> to show our app's header:</p>
<pre><code class="lang-js">&lt;button on:click={<span class="hljs-function">() =&gt;</span> {showHeader = <span class="hljs-literal">true</span>}}&gt;show&lt;/button&gt;
</code></pre>
<p>And what a header it is..!
<a target="_blank" href="https://scrimba.com/p/pG6X6UG/caZ3J6U3?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/czgdba1dpkzu552kq2hq.png" alt="header made visible on the DOM with an event handler" width="404" height="379" loading="lazy"></a>
<em>(Click the image to access the course.)</em></p>
<p>There is a gotcha with this, though - it only works with the native HTML <code>&lt;button&gt;</code> tag and not imported components called <code>&lt;Button&gt;</code>. </p>
<p>Luckily, we can work around this by using <strong>event forwarding</strong>, i.e. adding an <code>on:click</code> to the native <code>&lt;button&gt;</code> tag in its component file:</p>
<pre><code class="lang-js">&lt;button on:click&gt;
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span>
&lt;/button&gt;
</code></pre>
<h2 id="heading-event-dispatching">Event dispatching</h2>
<p><a target="_blank" href="https://scrimba.com/p/pG6X6UG/cD4bKDuD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article"><img src="https://dev-to-uploads.s3.amazonaws.com/i/w203a2wxgn1brk5ss6i4.png" alt="Hide and show buttons created with event dispatcher" width="404" height="381" loading="lazy"></a>
<em>(Click the image to access the course.)</em>
Event dispatching is a great feature of Svelte which increases code usability by allowing us to use the same element for more than one action.</p>
<p>In <a target="_blank" href="https://scrimba.com/p/pG6X6UG/cD4bKDuD?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">this scrim</a>, we learn how to use one <code>&lt;Button&gt;</code> component to both show and hide an element. </p>
<p>We create an event dispatcher in the <code>&lt;Button&gt;</code> component file like this:</p>
<pre><code class="lang-js">&lt;script&gt;
    <span class="hljs-keyword">import</span> {createEventDispatcher} <span class="hljs-keyword">from</span> <span class="hljs-string">'svelte'</span>;
    <span class="hljs-keyword">const</span> dispatch = createEventDispatcher();    
&lt;/script&gt;
</code></pre>
<p>We then add the dispatcher to our native HTML <code>&lt;button&gt;</code> like this:</p>
<pre><code class="lang-js">&lt;button on:click={<span class="hljs-function">() =&gt;</span> dispatch(<span class="hljs-string">'show'</span>)}&gt;
    Show
&lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">on:click</span>=<span class="hljs-string">{()</span> =&gt;</span> dispatch('hide')}&gt;
    Hide
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre>
<p>Lastly, we declare the button's functionality options in the <code>App.svelte</code> file as follows: </p>
<pre><code class="lang-js">&lt;Buttons on:show={<span class="hljs-function">() =&gt;</span> {showHeader = <span class="hljs-literal">true</span>}} on:hide={<span class="hljs-function">() =&gt;</span> {showHeader = <span class="hljs-literal">false</span>}} /&gt;
</code></pre>
<p>We can refactor this by passing values up through the dispatch using the event variable (<code>e</code>). In this case, the <code>&lt;Button&gt;</code> in our <code>App.svelte</code> file looks like this:</p>
<pre><code class="lang-js">&lt;Buttons on:click={<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {showHeader = e.detail}} /&gt;
</code></pre>
<p>While the native HTML <code>&lt;button&gt;</code>s in our component file look like this:</p>
<pre><code class="lang-js">&lt;button on:click={<span class="hljs-function">() =&gt;</span> dispatch(<span class="hljs-string">'click'</span>, <span class="hljs-literal">true</span>)}&gt;
    Show
&lt;/button&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">on:click</span>=<span class="hljs-string">{()</span> =&gt;</span> dispatch('click', false)}&gt;
    Hide
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre>
<h2 id="heading-reactivity">Reactivity</h2>
<p>If you want a piece of code to rerun every time its associated variable is updated, then Svelte's unique feature, <a target="_blank" href="https://scrimba.com/p/pG6X6UG/caZ3yBAB?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">the reactive statement</a>, is for you. We declare a reactive statement with <code>$:</code> as follows: </p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> score = <span class="hljs-number">0</span>;
    $: smileySays = <span class="hljs-string">'Hi there, your score is: '</span> + score;
</code></pre>
<p>It's also possible to run if statements inside reactive statements. The code to do so looks like this:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> score = <span class="hljs-number">0</span>;
    $: smileySays = <span class="hljs-string">'Hi there, your score is: '</span> + score;
    $: <span class="hljs-keyword">if</span> (score &lt; <span class="hljs-number">-4</span>) smileySays = <span class="hljs-string">'Wow your score is low!'</span>
</code></pre>
<p>That's about all the features we can cram into our 5-minute tour of Svelte. I hope you found it useful and are inspired to try out the framework for yourself and test your new-found skills. </p>
<p>Don't forget to check out the full course <a target="_blank" href="https://scrimba.com/course/glearnsvelte?utm_source=dev.to&amp;utm_medium=referral&amp;utm_campaign=glearnsvelte_5_minute_article">over at Scrimba</a> to find out about even more Svelte features and give the coding challenges a try.</p>
<p>Wherever your coding journey takes you next, happy learning :) </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Tailwind CSS and How Can I Add it to my Website or React App? ]]>
                </title>
                <description>
                    <![CDATA[ CSS is a technology that can be your best or worst friend. While it's incredibly flexible and can produce what seems like magic, without the proper care and attention, it can become hard to manage like any other code.  How can Tailwind CSS help us to... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-tailwind-css-and-how-can-i-add-it-to-my-website-or-react-app/</link>
                <guid isPermaLink="false">66b8e39e0196ee8e3efce546</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS3 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer Tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ front end ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ frontend ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PostCSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tailwind ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tools ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Tue, 19 May 2020 14:45:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/tailwind-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS is a technology that can be your best or worst friend. While it's incredibly flexible and can produce what seems like magic, without the proper care and attention, it can become hard to manage like any other code. </p>
<p>How can Tailwind CSS help us to take control of our styles?</p>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-tailwind">What is Tailwind?</a></li>
<li><a class="post-section-overview" href="#heading-so-what-makes-tailwind-great">So what makes Tailwind great?</a></li>
<li><a class="post-section-overview" href="#heading-part-1-adding-tailwind-css-to-a-static-html-page">Part 1: Adding Tailwind CSS to a static HTML page</a></li>
<li><a class="post-section-overview" href="#heading-part-2-adding-tailwind-css-to-a-react-app">Part 2: Adding Tailwind CSS to a React app</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/7KeZcRMltP0" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-what-is-tailwind">What is Tailwind?</h2>
<p><a target="_blank" href="https://tailwindcss.com/">Tailwind CSS</a> is a "utility-first" CSS framework that provides a deep catalog of CSS classes and tools that lets you easily get started styling your website or application.</p>
<p>The underlying goal is that as you're building your project, you don't need to deal with cascading styles and worrying about how to override that 10-selector pileup that's been haunting your app for the last 2 years.</p>
<h2 id="heading-so-what-makes-tailwind-great">So what makes Tailwind great?</h2>
<p>Taildwind's solution is to provide a wide variety of CSS classes that each have their own focused use. Instead of a class called <code>.btn</code> that is created with a bunch of CSS attributes directly, in Tailwind, you would either apply a bunch of classes like <code>bg-blue-500 py-2 px-4 rounded</code> to the button element or build a <code>.btn</code> class by <a target="_blank" href="https://tailwindcss.com/docs/functions-and-directives/#apply">applying</a> those utility class to that selector.</p>
<p>While Tailwind has a lot more going for it, we're going to focus on these basics for this tutorial, so let's dig in!</p>
<h2 id="heading-part-1-adding-tailwind-css-to-a-static-html-page">Part 1: Adding Tailwind CSS to a static HTML page</h2>
<p>We're going to start off by applying Tailwind CSS straight to a static HTML page. The hope is that by focusing on Tailwind and not the app, we can get a better understanding of what's actually happening with the framework.</p>
<h3 id="heading-step-1-creating-a-new-page">Step 1: Creating a new page</h3>
<p>You can get started by simply creating a new HTML file. For the content, you can use whatever you want, but I'm going to use <a target="_blank" href="http://fillerama.io/">fillerama.io</a> so the filler content is a bit more fun.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-with-content.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New HTML page with content</em></p>
<p>If you want to simplify this step, you can just <a target="_blank" href="https://github.com/colbyfayock/my-tailwind-static/commit/c7db11899c9cd193cdd666fd228cfaefe75623f2#diff-eacf331f0ffc35d4b482f1d15a887d3b">copy the file I created</a> to get started.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-static/commit/c7db11899c9cd193cdd666fd228cfaefe75623f2">Follow along with the commit!</a></p>
<h3 id="heading-step-2-adding-tailwind-css-via-cdn">Step 2: Adding Tailwind CSS via CDN</h3>
<p>Tailwind typically recommends that you install through <a target="_blank" href="https://www.npmjs.com/package/tailwindcss">npm</a> to get the full functionality, but again, we're just trying to understand how this works first.</p>
<p>So let's add a link to the CDN file in the <code>&lt;head&gt;</code> of our document:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>&gt;</span>
</code></pre>
<p>Once you save and reload the page, the first thing you'll notice is that all of the styles were stripped!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-tailwind-base.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with the Tailwind CSS base</em></p>
<p>This is expected. Tailwind includes a set of <a target="_blank" href="https://tailwindcss.com/docs/preflight">preflight styles</a> to fix cross-browser inconsistencies. For one, they include the popular <a target="_blank" href="https://github.com/necolas/normalize.css/">normalize.css</a> which they build upon with their own styles.</p>
<p>But we're going to learn how to use Tailwind to add back our styles and set things up how we want!</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-static/commit/b431b75cee0a03154a70b194b6dfcf028bc65942">Follow along with the commit!</a></p>
<h3 id="heading-step-3-using-tailwind-css-to-add-styles-to-your-page">Step 3: Using Tailwind CSS to add styles to your page</h3>
<p>Now that we have Tailwind installed, we've added the ability to make use of their huge library of utility classes that we'll now use to add styles back to our page.</p>
<p>Let's start off by adding some margin to all of our paragraphs (<code>&lt;p&gt;</code>) and our list elements (<code>&lt;ol&gt;</code>, <code>&lt;ul&gt;</code>). We can do this by adding the <code>.my-5</code> class to each element like so:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"my-5"</span>&gt;</span>
  Bender, quit destroying the universe! Yeah, I do that with my stupidness. I never loved you. Moving along…
  Belligerent and numerous.
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>The class name follows a pattern that you'll notice with the rest of the utility classes – <code>.my-5</code> stands for margin (m) applied to the y-axis (y) with a value of 5 which in Tailwind's case, it uses <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units">rem</a>, so the value is 5rem.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-paragraph-styles.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with basic paragraph styles</em></p>
<p>Next, let's make our headers look like actual headers. Starting with our <code>h1</code> tag, let's add:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-2xl font-bold mt-8 mb-5"</span>&gt;</span>
</code></pre>
<p>Here's what's happening:</p>
<ul>
<li><code>text-2xl</code>: set the text size (font-size) to 2xl. In Tailwind, that 2xl will equate to 1.5rem</li>
<li><code>font-bold</code>: set the weight of the text (font-weight) to bold</li>
<li><code>mt-8</code>: Similar to <code>my-5</code>, this will set the margin top (t) to 8rem</li>
<li><code>mb-5</code>: And this will set the margin bottom (b) to 5rem</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-header-styles.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with styled H1</em></p>
<p>With those classes added to the <code>h1</code>, let's apply those same exact classes to the rest of our header elements, but as we go down the list, reduce the size of the font size, so it will look like:</p>
<ul>
<li>h2: <code>text-xl</code></li>
<li>h3: <code>text-lg</code></li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-all-headers-style.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with all headers styled</em></p>
<p>Now let's make our list elements look like lists. Starting with our unordered list (<code>&lt;ul&gt;</code>), let's add these classes:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"list-disc list-inside my-5 pl-2"</span>&gt;</span>
</code></pre>
<p>Here's what we're adding:</p>
<ul>
<li><code>list-disc</code>: set the list-style-stype to disc (the markers on each line item)</li>
<li><code>list-inside</code>: sets the position of the list markers using  relative to the list items and the list itself with list-style-position to inside</li>
<li><code>my-5</code>: set the margin of the y axis to 5rem</li>
<li><code>pl-2</code>: set the left padding to 2rem</li>
</ul>
<p>Then we can apply the exact same classes to our ordered list (<code>&lt;ol&gt;</code>), except instead of <code>list-disc</code>, we want to change our style type to <code>list-decimal</code>, so that we can see numbers given it's an ordered list.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"list-decimal list-inside my-5 pl-2"</span>&gt;</span>
</code></pre>
<p>And we have our lists!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-styled-lists.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with styled lists</em></p>
<p>Finally, let's make our content a little easier to read by setting a max width and centering the content. On the <code>&lt;body&gt;</code> tag, add the following:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"max-w-4xl mx-auto"</span>&gt;</span>
</code></pre>
<p>/Note: Typically you wouldn't want to apply these classes to the <code>&lt;body&gt;</code> itself, rather, you can wrap all of your content with a <code>&lt;main&gt;</code> tag, but since we're just trying to get an idea of how this works, we'll roll with this. Feel free to add the <code>&lt;main&gt;</code> tag with those classes instead if you prefer!/</p>
<p>And with that, we have our page!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-content-centered.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with centered content</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-static/commit/06fd719c98d17e2242b61ec2ab7034436c1c2ba6">Follow along with the commit!</a></p>
<h3 id="heading-step-4-adding-a-button-and-other-components">Step 4: Adding a button and other components</h3>
<p>For the last part of our static example, let's add a button.</p>
<p>The trick with Tailwind, is they intentionally don't provide pre-baked component classes with the idea being that likely people would need to override these components anyways to make them look how they wanted.</p>
<p>So that means, we're going to have to create our own using the utility classes!</p>
<p>First, let's add a new button. Somewhere on the page, add the following snippet. I'm going to add it right below the first paragraph (<code>&lt;p&gt;</code>) tag:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Party with Slurm!<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-unstyled-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with unstyled button</em></p>
<p>You'll notice just like all of the other elements, that it's unstyled, however, if you try clicking it, you'll notice it still has the click actions. So let's make it look like a button.</p>
<p>Let's add the following classes:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-white font-bold bg-purple-700 hover:bg-purple-800 py-2 px-4 rounded"</span>&gt;</span>
  Party with Slurm!
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>Here's a breakdown of what's happening:</p>
<ul>
<li><code>text-white</code>: we're setting our text color to white</li>
<li><code>font-bold</code>: set the weight of the text to bold (font-weight)</li>
<li><code>bg-purple-700</code>: set the background color of the button to purple with a shade of 700. The 700 is relative to the other colors defined as purple, you can find these values on their <a target="_blank" href="https://tailwindcss.com/docs/customizing-colors#default-color-palette">palette documentation page</a></li>
<li><code>hover:bg-purple-800</code>: when someone hovers over the button, set the background color to purple shade 800. Tailwind provides these helper classes that allow us to easily define interactive stiles with things like <a target="_blank" href="https://tailwindcss.com/course/hover-focus-and-active-styles/">hover, focus, and active modifiers</a></li>
<li><code>py-2</code>: set the padding of the y-axis to 2rem</li>
<li><code>px-4</code>: set the padding of the  x-axis to 4rem</li>
<li><code>rounded</code>: round the corners of the element by setting the border radius. With tailwind, it sets the border-radius value to .25rem</li>
</ul>
<p>And with all of that, we have our button!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-page-styled-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>HTML page with a styled button</em></p>
<p>You can apply this methodology to any other component that you'd like to build. Though it's a manual process, we'll find out how we can make this process easier when building in more dynamic projects like those based on React.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-static/commit/09312336dce316a75e8007d6c935133490f16c25">Follow along with the commit!</a></p>
<h2 id="heading-part-2-adding-tailwind-css-to-a-react-app">Part 2: Adding Tailwind CSS to a React app</h2>
<p>For more of a real-world use case, we're going to add Tailwind CSS to an app created with <a target="_blank" href="https://reactjs.org/docs/create-a-new-react-app.html">Create React App</a>.</p>
<p>First, we'll walk through the steps you need to take to add tailwind to your project using a fresh install of Create React App, then we'll use our content from our last example to recreate it in React.</p>
<h3 id="heading-step-1-spinning-up-a-new-react-app">Step 1: Spinning up a new React app</h3>
<p>I'm not going to detail this step out too much. The gist is we'll bootstrap a new React app using Create React App.</p>
<p>To get started, you can follow along <a target="_blank" href="https://reactjs.org/docs/create-a-new-react-app.html">with the directions</a> from the official React documentation:</p>
<p><a target="_blank" href="https://reactjs.org/docs/create-a-new-react-app.html">https://reactjs.org/docs/create-a-new-react-app.html</a></p>
<p>And once you start your development server, you should now see an app!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/create-react-app-starting-page.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Create React App starting page</em></p>
<p>Finally, let's migrate all of our old content to our app. To do this, copy everything inside of the <code>&lt;body&gt;</code> tag of our static example and paste it inside of the wrapper <code>&lt;div className="App"&gt;</code> in the new React project.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/code-migrating-content.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Migrating code to React app</em></p>
<p>Next, change all <code>class="</code> attributes from the content we pasted in to <code>className="</code> so that it's using proper React attributes:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/code-fixing-class-attribute.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Fixing class attribute in content</em></p>
<p>And lastly, replace the className <code>App</code> on our wrapper <code>&lt;div&gt;</code> to the classes we used on our static <code>&lt;body&gt;</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/code-wrapper-styles.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Adding wrapper styles to the app</em></p>
<p>Once you save your changes and spin back up your server, it will look deceivingly okay.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/react-app-basic-content.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>React app with basic content</em></p>
<p>React includes some basic styles itself, so while it looks okay, we're not actually using Tailwind yet. So let's get started by installing it!</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-dynamic/commit/57993883c77739f71072bcc02ed2398543efc2fd">Follow along with the commit!</a></p>
<h3 id="heading-step-2-installing-tailwind-in-your-react-app">Step 2: Installing Tailwind in your React app</h3>
<p>There are a few steps we'll need to go through in order to get Tailwind up and running on our app. Make sure you follow these steps carefully to ensure it's properly configured.</p>
<p>First, let's add our dependencies:</p>
<pre><code>yarn add tailwindcss postcss-cli autoprefixer
# or
npm install tailwindcss postcss-cli autoprefixer
</code></pre><p><a target="_blank" href="https://tailwindcss.com/docs/installation#4-process-your-css-with-tailwind">Per Tailwind's documentation</a>, we need to be able to process our styles so that they can be properly added to our pipeline. So in the above, we're adding:</p>
<ul>
<li><a target="_blank" href="https://tailwindcss.com/">tailwindcss</a>: the core Tailwind package</li>
<li><a target="_blank" href="https://github.com/postcss/postcss">postcss-cli</a>: Create React App already uses postcss, but we need to configure Tailwind to be part of that build process and run it's own processing</li>
<li><a target="_blank" href="https://github.com/postcss/autoprefixer">autoprefixer</a>: Tailwind doesn't include vendor prefixes, so we want to add autoprefixer to handle this for us. This runs as part of our postcss configuration</li>
</ul>
<p>We're also going to add two dev dependencies that make it easier to work with our code:</p>
<pre><code>yarn add concurrently chokidar-cli -D
# or
npm install concurrently chokidar-cli --save-dev
</code></pre><ul>
<li><a target="_blank" href="https://github.com/kimmobrunfeldt/concurrently">concurrently</a>: a package that lets us set up the ability to run multiple commands at once. This is helpful since we'll need to watch both the styles and React app itself.</li>
<li><a target="_blank" href="https://github.com/kimmobrunfeldt/chokidar-cli">chokidar-cli</a>: let's us watch files and run a command when changed. We'll use this to watch our CSS file and run the build process of the CSS on cahnge</li>
</ul>
<p>Next, let's configure postcss, so create a new file in the root of your project called <code>postcss.config.js</code> and include the following:</p>
<pre><code class="lang-js"><span class="hljs-comment">// Inside postcss.config.js</span>
<span class="hljs-built_in">module</span>.exports = {
    <span class="hljs-attr">plugins</span>: [
        <span class="hljs-built_in">require</span>(<span class="hljs-string">'tailwindcss'</span>),
        <span class="hljs-built_in">require</span>(<span class="hljs-string">'autoprefixer'</span>)
    ],
};
</code></pre>
<p>This will add the Tailwindcss and Autoprefixer plugins to our postcss config.</p>
<p>With our configuration, we need to include it as part of the build and watch processes. Inside <code>package.json</code>, add the following to definitions to your <code>scripts</code> property:</p>
<pre><code class="lang-json"><span class="hljs-string">"build:css"</span>: <span class="hljs-string">"tailwind build src/App.css -o src/index.css"</span>,
<span class="hljs-string">"watch:css"</span>: <span class="hljs-string">"chokidar 'src/App.css' -c 'npm run build:css'"</span>,
</code></pre>
<p>Additionally, modify the <code>start</code> and <code>build</code> scripts to now include those commands:</p>
<pre><code class="lang-json"><span class="hljs-string">"start"</span>: <span class="hljs-string">"concurrently -n Tailwind,React 'npm run watch:css' 'react-scripts start'"</span>,
<span class="hljs-string">"build"</span>: <span class="hljs-string">"npm run build:css &amp;&amp; react-scripts build"</span>,
</code></pre>
<p>With our configuration ready to go, let's try our styles back to where they were when we left off from the static example.</p>
<p>Inside the <code>App.css</code> file, replace the entire content with:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@tailwind</span> base;
<span class="hljs-keyword">@tailwind</span> components;
<span class="hljs-keyword">@tailwind</span> utilities;
</code></pre>
<p>This is going to import Tailwind's base styles, components, and utility classes that allow Tailwind to work as you would expect it to.</p>
<p>We can also remove the <code>App.css</code> import from our <code>App.js</code> file because it's now getting injected directly into our <code>index.css</code> file. So remove this line:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;
</code></pre>
<p>Once you're done, you can start back up your development server! If it was already started, make sure to restart it so all of the configuration changes take effect.</p>
<p>And now the page should look exactly like it did in our static example!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/react-app-with-styled-content.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>React app with content styled</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-dynamic/commit/5f50cc218ef58f469dad7f09bdad31f36b58a896">Follow along with the commit!</a></p>
<h3 id="heading-step-3-creating-a-new-button-component-class-with-tailwind">Step 3: Creating a new button component class with Tailwind</h3>
<p>Tailwind doesn't ship with prebaked component classes, but it does make it easy to create them!</p>
<p>We're going to use our button that we already created as an example of creating a new component. We'll create a new class <code>btn</code> as well as a color modifier <code>btn-purple</code> to accomplish this.</p>
<p>The first thing we'll want to do is open up our App.css file where we'll create our new class. Inside that file, let's add:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.btn</span> {
  @apply font-bold py-2 px-4 rounded;
}
</code></pre>
<p>If you remember from our HTML, we're already including those same classes to our <code>&lt;button&gt;</code> element.  Tailwind let's us "apply" or include the styles that make up these utility classes to another class, in this case, the <code>.btn</code> class.</p>
<p>And now that we're creating that class, let's apply it to our button:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn text-white bg-purple-700 hover:bg-purple-800"</span>&gt;</span>
  Party with Slurm!
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>And if we open up our page, we can see our button still looks the same. If we inspect the element, we can see our new <code>.btn</code> class generated with those styles.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/react-tailwind-button-class.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>.btn class in a React app with Tailwind</em></p>
<p>Next, let's create a color modifier. Similar to what we just did, we're going to add the following rules:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.btn-purple</span> {
  @apply bg-purple-700 text-white;
}

<span class="hljs-selector-class">.btn-purple</span><span class="hljs-selector-pseudo">:hover</span> {
  @apply bg-purple-800;
}
</code></pre>
<p>Here, we're adding our background color and our text color to our button class. We're also applying a darker button color when someone hovers over the button.</p>
<p>We'll also want to update our HTML button to include our new class and remove the ones we just applied:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"btn btn-purple"</span>&gt;</span>
  Party with Slurm!
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>And with that change, we can still see that nothing has changed and we have our new button class!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/react-tailwind-styled-button.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Styled button in React with Tailwind</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-tailwind-dynamic/commit/7a76e8a4583b0a4c523ea902d73e889c7b86f437">Follow along with the commit!</a></p>
<h2 id="heading-applying-these-concepts-to-more-components">Applying these concepts to more components</h2>
<p>Through this walkthrough, we learned how to create a new component class using the Tailwind apply directive. This allowed us to create reusable classes that represent a component like a button.</p>
<p>We can apply this to any number of components in our design system. For instance, if we wanted to always show our lists the way we set them up here, we could create a <code>.list-ul</code> class that represented an unordered list with the Tailwind utilities <code>list-disc list-inside my-5 pl-2</code> applied.</p>
<h2 id="heading-what-tips-and-tricks-do-you-like-to-use-with-tailwind">What tips and tricks do you like to use with Tailwind?</h2>
<p>Share with me on <a target="_blank" href="https://twitter.com/colbyfayock">Twitter</a>!</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Best AI & Machine Learning Frameworks to Learn for Web Development ]]>
                </title>
                <description>
                    <![CDATA[ By Rashmi Sharma In this highly competitive tech market space, companies are always looking to get a leg up on their competitors through the best web design and development.  But when you're building a modern business app, you need to keep market com... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/best-ai-machine-learning-frameworks-for-web-development/</link>
                <guid isPermaLink="false">66d460c79f2bec37e2da0668</guid>
                
                    <category>
                        <![CDATA[ Artificial Intelligence ]]>
                    </category>
                
                    <category>
                        <![CDATA[ framework ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Machine Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 14 May 2020 18:24:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/photo-1471009544976-30d2142adb6b.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Rashmi Sharma</p>
<p>In this highly competitive tech market space, companies are always looking to get a leg up on their competitors through the best web design and development. </p>
<p>But when you're building a modern business app, you need to keep market competition and <a target="_blank" href="https://syncrasytech.com/blogs/digital-experience-management-trends-2020">digital experience trends</a> in perspective for a modernized and marketable application for your business. </p>
<p>But before you do that, I will give you some information about the role of artificial intelligence in web development. Then we will see some of the most popular AI and machine learning frameworks for building web apps in 2020. </p>
<p>So now let’s understand the role of AI and machine learning in web development.</p>
<h2 id="heading-the-relevance-of-ai-and-machine-learning-in-web-development">The Relevance of AI and Machine Learning In Web Development</h2>
<p>Artificial Intelligence and Machine Learning are popular technologies that allow web applications to learn and observe from a user's preferences and habits. </p>
<p>AI-enabled websites are on-trend everywhere. One reason is that AI uses genetic algorithms and neural networks to build artificial intelligence into web applications from scratch. And this is now easy to implement for most companies.</p>
<h2 id="heading-why-incorporate-ai-and-machine-learning-into-your-web-development-process">Why Incorporate AI and Machine Learning into Your Web Development Process?</h2>
<h3 id="heading-they-delight-your-customer-support-team">They Delight Your Customer Support Team</h3>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/enricomolinari/status/1257664594627067905?s=20"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Setting up an AI chatbot on your website can improve the whole customer support experience and can help you provide your users much better assistance. </p>
<p>It communicates naturally, understands your emotions, and can respond to the most complex questions, even if the questions are not connected to your product, service or industry. So, if you want to grow your business and take your business to the next level, do not hesitate to implement a AI chatbot.</p>
<h3 id="heading-examples-of-chatbots-available-on-the-web">Examples of Chatbots Available on the Web:</h3>
<p><strong><a target="_blank" href="https://www.capitalone.com/learn-grow/money-management/eno-chatbot-banking-conversations-next-level/">Capital One's "Eno"</a>:</strong> Capital One is a banking organization that offers financial products and surveys. They use Eno, a chatbot to help customers manage their queries related to their transactions, account balances, and analyzing their spending habits.</p>
<p><strong><a target="_blank" href="http://medwhat.com/">MedWhat's Virtual Medical Assistant</a>:</strong> Powered by machine learning, the MedWhat’s chatbot provides quick responses to questions based on behaviors that it learns by interacting with users. This chatbot makes it easier for both patients and doctors to discuss and diagnose health issues in a faster, easier, and more transparent manner.</p>
<p><strong><a target="_blank" href="https://www.chatbotguide.org/dominospizza-bot">Domino’s “Dom”</a></strong>: This is the interactive Pizza Bot that allows you to order food from the Domino’s site. The Domino’s chatbot offer sa full pizza menu, tracks deliveries, and can also track your previous orders and consider them for re-ordering.</p>
<h3 id="heading-they-help-maximize-user-experience-ux">They Help Maximize User Experience (UX)</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/ai-ux_firebase-churn-prevention-machine-learning-720x329.png" alt="Image" width="600" height="400" loading="lazy">
<em>AI UX (Image Source: <a target="_blank" href="https://uxstudioteam.com/ux-blog/ai-ux/">uxstudioteam.com</a>)</em></p>
<p>AI and machine learning help you understand your customer’s preferences. A website with AI and ML features helps you analyze your customer’s preferences, search history, and even location. This way you will be able to design and improve your website according to the needs of your customers. You can also give them a better customer experience by updating your UI accordingly.</p>
<p>Implementing AI solutions to your online shop will help give your customers a more personalized shopping experience, as if everything was created exactly for them only. AI and machine learning creates a real world atmosphere on your website that motivates customers to make a purchase.</p>
<p>Take Amazon.com as an example – it's of one of the biggest online shopping portals and it uses AI and ML for product recommendations. It also helps the company identify user preferences, and all this is based on previously tracked data by Amazon’s AI solution.</p>
<h3 id="heading-they-provide-fast-access-to-information">They Provide Fast Access to Information</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/Narvar-Report-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Voice-Based Search Functions (Image Source: <a target="_blank" href="https://www.dialogtech.com/blog/voice-search-statistics/">www.dialogtech.com</a>)</em></p>
<p>Business owners are looking to add voice-based search functions to their websites, as it is becoming more and more popular. Apps like Google Assistant, Siri, and Cortana that support voice-enabled search functions give users fast access to information. </p>
<p>Suppose you are an online clothing retailer. You can use voiced-based search systems to help your customers find the clothing types they want with complete product information such as price of the item, fabric type, size, color, and length.</p>
<h3 id="heading-they-streamline-your-marketing-strategy">They Streamline Your Marketing Strategy</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/17135.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>AI in Marketing (Image Source: <a target="_blank" href="https://www.statista.com/chart/17135/artificial-intelligence-marketing/">www.statista.com)</a></em></p>
<p>Artificial Intelligence and Machine Learning technology have been used by marketing teams for making major marketing decisions and market predictions based on what is in demand. </p>
<p>The technology works by analyzing a user’s behavior by finding out what type of products a user likes and other preferences. This data will help marketing teams to decide what changes should be done in order to increase sales and improve conversion rate.</p>
<p>The potential of AI and machine learning in web development hasn't escaped the attention of top companies such as Google, Facebook, IBM, and Microsoft Launch. </p>
<p>They've all come out with <a target="_blank" href="https://www.tessella.com/insights/open-artificial-intelligence-api-ai">AI toolkits and APIs</a> for featuring natural language understanding and machine learning features in modern web applications. </p>
<p>Learning to integrate and implement AI technology into your site is definitely feasible.</p>
<h2 id="heading-top-ai-and-machine-learning-frameworks-for-web-development">Top AI and Machine Learning Frameworks For Web Development</h2>
<p>But the bottom line comes down to how effectively business leaders implement AI into their web development processes. </p>
<p>To help you out, here are five innovative AI and machine learning frameworks for web development to keep an eye on in 2020 and beyond.</p>
<h3 id="heading-tensorflowhttpswwwtensorfloworg"><a target="_blank" href="https://www.tensorflow.org/">TensorFlow</a></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-110.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Quick</strong> <strong>stats</strong>:</p>
<ul>
<li><strong>Developed By:</strong> Google Brain Team</li>
<li><strong>Founded In:</strong> November 2015</li>
<li><strong>Written In:</strong> C++, Python, and CUDA</li>
<li><strong>Platforms:</strong> Linux, macOS, Microsoft Windows, Android, JavaScript</li>
<li><strong>Latest Release:</strong> 2.1.0 / January 8, 2020</li>
<li><strong>Architecture:</strong> Flexible for cross-platform development</li>
</ul>
<p>Ever since its introduction in the year 2015, TensorFlow has been a favorite machine learning framework amongst the web developers. This is because the Google Brain Team, the creator of the framework, has built it in such a way that it lets developers use machine learning in JavaScript or in Node for numerical computation at once. </p>
<p>It also helps teams build web applications using machine learning models with JavaScript and its modules which are responsible for recognizing different core functionalities of real-world interactions and objects. </p>
<p>It brings the features of AI and machine learning technology to the front-end, so the users can have real-time experiences of the real-world from a web browser. </p>
<p>Businesses of all sizes are using the Tensorflow machine learning framework for transforming their web development process so that the end-users can leverage the benefits of machine learning and AI predictive analysis.</p>
<p>Model building is greatly influencing the web development process. And TensorFlow uses multiple abstractions and powerful libraries to form and train models for the creation of complex technologies. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-115.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The result is code with some higher-order functionality, as well as code that is easier to read, write, debug, and work with. TensorFlow uses the high-level <a target="_blank" href="https://machinelearningmastery.com/keras-functional-api-deep-learning/">Keras API</a> that not only makes the code cleaner, but can also reduce the code length to create the models.</p>
<p>After creating models, you can apply <a target="_blank" href="https://www.tensorflow.org/guide/distributed_training">distributed methods in TensorFlow</a> to reduce the training time of the neural network models on different servers. The idea is that you can perform multiple coding experiments over different servers. With full control over the servers, TensorFlow allows developers to experiment with code that occurs in the network for any operation. </p>
<p>All these features and functionalities help you get started with TensorFlow easily.</p>
<h3 id="heading-apache-mahouthttpsmahoutapacheorg"><a target="_blank" href="https://mahout.apache.org/">Apache Mahout</a></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-111.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Quick</strong> <strong>stats</strong>:</p>
<ul>
<li><strong>Developed By:</strong> Apache Software Foundation</li>
<li><strong>Founded In:</strong> April 2008</li>
<li><strong>Written In:</strong> Java and Scala</li>
<li><strong>Latest Release:</strong> 0.14.0 / 6 March 2019</li>
<li><strong>Platforms:</strong> Apache Hadoop, Apache Spark, Apache Flink, Scala+</li>
<li><strong>Architecture:</strong> Flexible for cross-platform development</li>
</ul>
<p>The Apache Software Foundation along with a group of developers maintains Apache Mahout. It is an open source machine learning framework that allows web app developers to design huge web applications. These applications are designed to help data scientists and statisticians to perform various mathematical algorithms.</p>
<p>Professional web developers recommend this framework in 2020 because it improves the performance of web applications by using <a target="_blank" href="https://mahout.apache.org/docs/latest/algorithms/linear-algebra/">distributed linear algebra frameworks</a> with mathematically expressive R-Like Scala DSL for distributed algorithms. It also offers scalability, simplicity, and speed.</p>
<p>Mahout uses the Apache Hadoop library to build scalable supervised and unsupervised machine learning systems in the cloud. Developers can use Mahout for creating recommendation-based engines to perform functions such as classification as well as grouping and mining large volumes of data.</p>
<p>Apache Mahout has the clustering implementations that are supported by <a target="_blank" href="https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781783284436/1/ch01lvl1sec12/clustering-algorithms-in-mahout">algorithms</a> like K-Means, Canopy, Spectral, Dirichlet, Fuzzy K-Means, and Streaming K-Means. <a target="_blank" href="https://www.tutorialspoint.com/mahout/mahout_clustering.htm">Clustering</a> can help developers to discover and organize elements in distinct groups based on the similarity between items. </p>
<p>This is why the Mahout-based web applications can characterize their customer groups based on purchasing patterns, product classifications, and grouping of items.</p>
<h3 id="heading-microsoft-cognitive-toolkithttpswwwmicrosoftcomen-usresearchproductcognitive-toolkitlangfrca"><a target="_blank" href="https://www.microsoft.com/en-us/research/product/cognitive-toolkit/?lang=fr_ca">Microsoft Cognitive Toolkit</a></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-112.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Quick stats</strong>:</p>
<ul>
<li><strong>Developed By:</strong> Microsoft Research</li>
<li><strong>Founded In:</strong> 2016</li>
<li><strong>Written In:</strong> C++ and Python</li>
<li><strong>Latest Release:</strong> 2.7.0 / 26 April 2019</li>
<li><strong>Platforms:</strong> Windows, Linux</li>
<li><strong>Model Types:</strong> Support feed-forwards DNNs, convolutional and recurrent neural networks</li>
</ul>
<p>Microsoft Cognitive Toolkit is yet another open-source deep learning framework. You can add it to web programs through high-level and low-level APIs for building neural networks. It passes knowledge to web programs through API optimizers and offers a number of components to measure the performance of neural networks.</p>
<p>If you want to create dynamic web applications, it is a perfect deep learning framework. Thanks to its functionality, scalability, and speed, you can keep cumbersomeness coding at bay. CNTK based web applications are efficient for image recognition, voice recognition, handwriting. </p>
<p>It supports both convolutional neural networks (CNNs) and recurrent neural networks (RNNs/LSTMs). CNTK is an extensible library and you can also use this in your <a target="_blank" href="https://docs.microsoft.com/en-us/cognitive-toolkit/">Python, C#, or C++ programs</a>, or as a machine-learning tool through its own model description language (BrainScript). </p>
<p>Additionally, it boasts 64-bit Linux or 64-bit Windows operating systems that you can install from the pre-compiled binary packages, or from the <a target="_blank" href="https://github.com/Microsoft/CNTK">GitHub</a> library.</p>
<p>Its support for the <a target="_blank" href="https://onnx.ai/">ONNX format</a> (Open Neural Network Exchange) greatly influences the web development process with AI and machine learning technology. It uses AI models with a variety of frameworks, tools, runtimes, and compilers. This is why CNTK is one of the best machine learning frameworks in areas such as speech recognition, predictive analysis, and understanding large unstructured datasets. </p>
<p>Many big tech companies use this framework for their web development because of its capabilities in these areas.</p>
<h3 id="heading-caffe2httpscaffe2ai"><a target="_blank" href="https://caffe2.ai/">Caffe2</a></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-114.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Quick stats</strong>:</p>
<ul>
<li><strong>Developed By:</strong> Berkeley Vision and Learning Center</li>
<li><strong>Founded In:</strong> 2017</li>
<li><strong>Written In:</strong> C++ and Python</li>
<li><strong>Latest Release:</strong> 1.0 / 18 April 2017</li>
<li><strong>Platforms:</strong> Linux, macOS, Windows</li>
<li><strong>Architecture:</strong> Expressive and allow innovation in web development</li>
</ul>
<p>This is a perfect deep learning framework for those who think that big things come in small packages. Yes, if you are looking for a flexible deep learning framework, Caffe2 is what you should go for. Developers love to use it as it is flexible and easy to develop code. </p>
<p>With the help of extensible code, it enhances your application's performance. The best part is developers just need to have basic knowledge of <a target="_blank" href="https://caffe2.ai/docs/caffe-migration.html">C++ source code</a>. </p>
<p>It offers bindings for Python and MATLAB. And, your app code won't be complicated, as it supports state of the art code and models. It has pre-trained networks of <a target="_blank" href="https://caffe2.ai/docs/zoo.html">Caffe2 Model Zoo</a> for scenarios that include web development and research experiments. </p>
<p>One of its biggest benefits is its speed – it can process over <a target="_blank" href="https://caffe.berkeleyvision.org/">60M of images</a> on a daily basis with a single Nvidia K40 GPU.</p>
<p>There are various firms using the Caffe2 deep learning framework for building web apps with image segmentation and classification features. Caffe2 is able to provide a swift and fast development process that is mainly possible because of its <a target="_blank" href="https://contentlab.io/an-introduction-to-convolutional-neural-networks-and-deep-learning-with-caffe/">convolutional neural networks</a>. </p>
<p>Also if you use the Caffe2 Model Zoo with a set of the pre-trained models you can opt for a complete no-code development process.</p>
<h3 id="heading-apache-singahttpssingaapacheorg"><a target="_blank" href="https://singa.apache.org/">Apache Singa</a></h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-113.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Quick stats</strong>:</p>
<ul>
<li><strong>Developed By:</strong> Apache Software Foundation</li>
<li><strong>Founded In:</strong> September 2015</li>
<li><strong>Written In:</strong> C++, Python, Java</li>
<li><strong>Latest Release:</strong> 3.0.0 / April 20, 2020</li>
<li><strong>Platforms:</strong> Linux, macOS, Windows</li>
<li><strong>Architecture:</strong> Logical system to support distributed training frameworks</li>
</ul>
<p>Last, but not the least, Apache Singa is a popularly used deep learning framework for web development. It is quite versatile and developers can use it for creating web applications for an array of businesses. It offers several advantages, not just to the app developers but also to app owners. </p>
<p>Apache Singa has numerous features including flexible architecture for distributed training, and three main <a target="_blank" href="http://edubulls.in/deep-learnin-with-apache-singa-r-training.php">components</a>:</p>
<ul>
<li>the Core component for memory management,</li>
<li>the IO component for data analysis, and </li>
<li>the Model component for NLP and image recognition. </li>
</ul>
<p>Currently, the Apache Singa team is working on the idea of <a target="_blank" href="https://jaxenter.com/apache-singa-top-level-project-163850.html">SINGA-lite and Singa-Easy</a> for making AI and deep learning more accessible and easy to use for developers.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/ApacheSinga/status/1120935368688377857?s=20"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>If you are looking for an extremely popular, secure, speedy, and flexible framework for building deep learning models, Apache Singa is what you need to go for in the year 2020. </p>
<p>At present, SINGA systems have been applied to <a target="_blank" href="https://www.computerweekly.com/news/252473678/Singapore-makes-mark-on-AI-with-Apache-Singa">healthcare apps</a> for analyzing electronic medical record (EMR) data. There are many more companies using Apache SINGA to build useful data types applications.</p>
<h2 id="heading-in-the-end">In the End</h2>
<p>You might have already heard about all these AI and machine learning frameworks for web development. There are, of course, other frameworks out there. But according to my analysis, these 5 frameworks will be the winners this year.</p>
<p>You can use these frameworks for building awesome web apps and reaching out to your users worldwide through your web apps. This will help you increase your customer base, which in turn leads to the success of your business. </p>
<p>If you need services like that, and don't have the resources to set them up yourself, then you should hire a company that offers custom web development services according to your requirements. </p>
<p>You can contact my team at <a target="_blank" href="https://syncrasytech.com/">Syncrasy Tech</a> for more details on AI enabled web development services. Or contact us <a target="_blank" href="https://syncrasytech.com/contact-us">here</a>. </p>
<p>If you have any queries, you can reach out here on <a target="_blank" href="https://www.linkedin.com/company/syncrasy-tech/">LinkedIn</a>.</p>
<p><em>Thanks for reading!</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
