SlideShare a Scribd company logo
1 of 18
Download to read offline
Functional Components in Vue.js
What is a
functional
component?
Functional components (not to be confused with Vue’s render functions) is a
component which holds no state and no instance.
In more plain English, this means that the component does not support reactivity
and cannot make a reference to itself through the `this` keyword.
Implementation: <template>
Implementation: render()
Without the state or instance,
you might wonder how you can
reference things like data or
methods. Fortunately, Vue
provides a “context” parameter
to the underlying render function.
This “context” argument is an
object with the following
properties:
● props: An object of the provided props
● children: An array of the VNode children
● slots: A function returning a slots object
● scopedSlots: (v2.6.0+) An object that
exposes passed-in scoped slots. Also exposes
normal slots as functions.
● data: The entire data object, passed to the
component as the 2nd argument of
createElement
● parent: A reference to the parent component
● listeners: (v2.3.0+) An object containing
parent-registered event listeners. This is an
alias to data.on
● injections: (v2.3.0+) if using the inject
option, this will contain resolved injections.
Accessing this “context” parameter is pretty straightforward. For example, if we
wanted to do something with props, it might looks like this:
Implementation: <template>
Implementation: render()
Why are
functional
components cool?
Functional components can make accessing your components a little more difficult to
work with or introduce some complexity, so why go through the hassle?
Speed.
Because functional components do not have a state, they do not require extra
initialization for things like Vue’s reactivity system. Functional component will still
react to changes like new props being passed in, but within the component itself,
there is no way for it to know when it’s data has changed because it does not
maintain its own state.
For a large application, you will see significant improvements to the DOM
render/update events after implementing functional components.
When would you
use functional
components?
Functional components are probably not right for most cases. After all, the point of
using a JavaScript framework is to build applications which are more reactive. In
Vue, you cannot do this without the reactivity system in place.
There are, however, some
excellent use cases to sprinkle in
functional components:
● A component which is simply presentational.
AKA, a “dumb” component. For example:
buttons, pills, tags, cards, even full pages with
just static text like an About page.
● A “higher order component” which is used to
wrap markup or basic functionality around
another component.
● Any time you find yourself in a loop (v-for),
the items in the loop are usually great
candidates.
Caveats
There is one small issue I’ve run into for a pretty specific use case. When using a
<template> tag, and accepting data through a prop, sometimes we want to modify
the data inside the template. With a standard Vue component, this is easy using
either methods, or computed props. With functional components, we do not have
access to methods or computed props. However, there is still a way to do this.
Let’s say our component accepts a “user” prop which is an object with “firstName”
and “lastName”, and we want to render a template that shows the user’s full name
(let’s just assume we don’t want to simply provide a “fullName” prop”.
In a functional <template> component, the way we could do this is by providing a
method right on our component definition, then use the $options property provided
by Vue to access our special method:
Conclusion
If you care about performance or ar working on very large applications, consider
getting in the practice of creating functional components. The small learning curve is
worth the performance gains.
References:
https://vuejs.org/v2/guide/render-function.html#Functional-Components
https://itnext.io/whats-the-deal-with-functional-components-in-vue-js-513a31eb72b0

More Related Content

What's hot

Frontend War: Angular vs React vs Vue
Frontend War: Angular vs React vs VueFrontend War: Angular vs React vs Vue
Frontend War: Angular vs React vs VueMarudi Subakti
 
Full_Stack_Web_Development
Full_Stack_Web_DevelopmentFull_Stack_Web_Development
Full_Stack_Web_DevelopmentVasyl Stokolosa
 
React - поглянемо по іншому на V в MVC
React - поглянемо по іншому на V в MVCReact - поглянемо по іншому на V в MVC
React - поглянемо по іншому на V в MVCStfalcon Meetups
 
How to setup aws amplify in a vue project
How to setup aws amplify  in a vue projectHow to setup aws amplify  in a vue project
How to setup aws amplify in a vue projectyuxiang21
 
Sandeep Chauhan | Top java script frameworks in 2020
Sandeep Chauhan | Top java script frameworks in 2020Sandeep Chauhan | Top java script frameworks in 2020
Sandeep Chauhan | Top java script frameworks in 2020Sandeep Chauhan
 
Micro-Frontends JSVidCon
Micro-Frontends JSVidConMicro-Frontends JSVidCon
Micro-Frontends JSVidConAmir Zuker
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersLewiz
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentationJohn Staveley
 
JavaScript - Kristiansand PHP
JavaScript - Kristiansand PHPJavaScript - Kristiansand PHP
JavaScript - Kristiansand PHPholeedave
 
Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Sonal Raj
 
Interoperability of components built with different frameworks
Interoperability of components built with different frameworksInteroperability of components built with different frameworks
Interoperability of components built with different frameworksSouvik Basu
 
coursera-full-stack-web-development-specialization
coursera-full-stack-web-development-specializationcoursera-full-stack-web-development-specialization
coursera-full-stack-web-development-specializationMadrisan Davide
 
Progressive Web Apps – The Future of the Web World
Progressive Web Apps – The Future of the Web WorldProgressive Web Apps – The Future of the Web World
Progressive Web Apps – The Future of the Web WorldSystango
 
Improve your Web Development using Visual Studio 2010
Improve your Web Development using Visual Studio 2010Improve your Web Development using Visual Studio 2010
Improve your Web Development using Visual Studio 2010Suthep Sangvirotjanaphat
 
Top Frontend Framework 2022
Top Frontend Framework 2022Top Frontend Framework 2022
Top Frontend Framework 2022ElenorWisozk
 
Leveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergLeveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergFelix Arntz
 
Pros & cons of svelte
Pros & cons of sveltePros & cons of svelte
Pros & cons of svelteElenorWisozk
 
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)Windows Developer
 
Ajax with jquery and grails
Ajax with jquery and grailsAjax with jquery and grails
Ajax with jquery and grailsAndrej Koelewijn
 

What's hot (20)

Frontend War: Angular vs React vs Vue
Frontend War: Angular vs React vs VueFrontend War: Angular vs React vs Vue
Frontend War: Angular vs React vs Vue
 
Full_Stack_Web_Development
Full_Stack_Web_DevelopmentFull_Stack_Web_Development
Full_Stack_Web_Development
 
React - поглянемо по іншому на V в MVC
React - поглянемо по іншому на V в MVCReact - поглянемо по іншому на V в MVC
React - поглянемо по іншому на V в MVC
 
How to setup aws amplify in a vue project
How to setup aws amplify  in a vue projectHow to setup aws amplify  in a vue project
How to setup aws amplify in a vue project
 
Sandeep Chauhan | Top java script frameworks in 2020
Sandeep Chauhan | Top java script frameworks in 2020Sandeep Chauhan | Top java script frameworks in 2020
Sandeep Chauhan | Top java script frameworks in 2020
 
Wicket Web Framework 101
Wicket Web Framework 101Wicket Web Framework 101
Wicket Web Framework 101
 
Micro-Frontends JSVidCon
Micro-Frontends JSVidConMicro-Frontends JSVidCon
Micro-Frontends JSVidCon
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developers
 
Single Page Application presentation
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
 
JavaScript - Kristiansand PHP
JavaScript - Kristiansand PHPJavaScript - Kristiansand PHP
JavaScript - Kristiansand PHP
 
Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?Progressive Javascript: Why React when you can Vue?
Progressive Javascript: Why React when you can Vue?
 
Interoperability of components built with different frameworks
Interoperability of components built with different frameworksInteroperability of components built with different frameworks
Interoperability of components built with different frameworks
 
coursera-full-stack-web-development-specialization
coursera-full-stack-web-development-specializationcoursera-full-stack-web-development-specialization
coursera-full-stack-web-development-specialization
 
Progressive Web Apps – The Future of the Web World
Progressive Web Apps – The Future of the Web WorldProgressive Web Apps – The Future of the Web World
Progressive Web Apps – The Future of the Web World
 
Improve your Web Development using Visual Studio 2010
Improve your Web Development using Visual Studio 2010Improve your Web Development using Visual Studio 2010
Improve your Web Development using Visual Studio 2010
 
Top Frontend Framework 2022
Top Frontend Framework 2022Top Frontend Framework 2022
Top Frontend Framework 2022
 
Leveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in GutenbergLeveraging the Power of Custom Elements in Gutenberg
Leveraging the Power of Custom Elements in Gutenberg
 
Pros & cons of svelte
Pros & cons of sveltePros & cons of svelte
Pros & cons of svelte
 
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)
Build 2017 - P4099 - Production tracing with Event Tracing for Windows (ETW)
 
Ajax with jquery and grails
Ajax with jquery and grailsAjax with jquery and grails
Ajax with jquery and grails
 

Similar to Functional Components in Vue.js

Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperFabrit Global
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part IIMichael Fons
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Data Sharing Between Child and Parent Components in AngularJS
Data Sharing Between Child and Parent Components in AngularJSData Sharing Between Child and Parent Components in AngularJS
Data Sharing Between Child and Parent Components in AngularJSFibonalabs
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxBOSC Tech Labs
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesMarios Fakiolas
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistMark Fayngersh
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdfArthyR3
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 

Similar to Functional Components in Vue.js (20)

React patterns
React patternsReact patterns
React patterns
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
 
Vue.js basics
Vue.js basicsVue.js basics
Vue.js basics
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Knockout in action
Knockout in actionKnockout in action
Knockout in action
 
Data Sharing Between Child and Parent Components in AngularJS
Data Sharing Between Child and Parent Components in AngularJSData Sharing Between Child and Parent Components in AngularJS
Data Sharing Between Child and Parent Components in AngularJS
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
Get rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directivesGet rid of controllers in angular 1.5.x start using component directives
Get rid of controllers in angular 1.5.x start using component directives
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 

More from Austin Gil

What I like about vue
What I like about vueWhat I like about vue
What I like about vueAustin Gil
 
Enterprise level application in 5 min
Enterprise level application in 5 minEnterprise level application in 5 min
Enterprise level application in 5 minAustin Gil
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security PolicyAustin Gil
 
Developing word press professionally
Developing word press professionallyDeveloping word press professionally
Developing word press professionallyAustin Gil
 
A holistic approach to web performance
A holistic approach to web performanceA holistic approach to web performance
A holistic approach to web performanceAustin Gil
 
Web Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessWeb Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessAustin Gil
 
Improve WordPress load times with a CDN
Improve WordPress load times with a CDNImprove WordPress load times with a CDN
Improve WordPress load times with a CDNAustin Gil
 
Isotope, WP REST API, and AJAX...Oh my!
Isotope,  WP REST API, and AJAX...Oh my!Isotope,  WP REST API, and AJAX...Oh my!
Isotope, WP REST API, and AJAX...Oh my!Austin Gil
 

More from Austin Gil (8)

What I like about vue
What I like about vueWhat I like about vue
What I like about vue
 
Enterprise level application in 5 min
Enterprise level application in 5 minEnterprise level application in 5 min
Enterprise level application in 5 min
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security Policy
 
Developing word press professionally
Developing word press professionallyDeveloping word press professionally
Developing word press professionally
 
A holistic approach to web performance
A holistic approach to web performanceA holistic approach to web performance
A holistic approach to web performance
 
Web Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessWeb Performance: 3 Stages to Success
Web Performance: 3 Stages to Success
 
Improve WordPress load times with a CDN
Improve WordPress load times with a CDNImprove WordPress load times with a CDN
Improve WordPress load times with a CDN
 
Isotope, WP REST API, and AJAX...Oh my!
Isotope,  WP REST API, and AJAX...Oh my!Isotope,  WP REST API, and AJAX...Oh my!
Isotope, WP REST API, and AJAX...Oh my!
 

Recently uploaded

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Functional Components in Vue.js

  • 3. Functional components (not to be confused with Vue’s render functions) is a component which holds no state and no instance. In more plain English, this means that the component does not support reactivity and cannot make a reference to itself through the `this` keyword.
  • 6. Without the state or instance, you might wonder how you can reference things like data or methods. Fortunately, Vue provides a “context” parameter to the underlying render function. This “context” argument is an object with the following properties: ● props: An object of the provided props ● children: An array of the VNode children ● slots: A function returning a slots object ● scopedSlots: (v2.6.0+) An object that exposes passed-in scoped slots. Also exposes normal slots as functions. ● data: The entire data object, passed to the component as the 2nd argument of createElement ● parent: A reference to the parent component ● listeners: (v2.3.0+) An object containing parent-registered event listeners. This is an alias to data.on ● injections: (v2.3.0+) if using the inject option, this will contain resolved injections.
  • 7. Accessing this “context” parameter is pretty straightforward. For example, if we wanted to do something with props, it might looks like this:
  • 11. Functional components can make accessing your components a little more difficult to work with or introduce some complexity, so why go through the hassle? Speed. Because functional components do not have a state, they do not require extra initialization for things like Vue’s reactivity system. Functional component will still react to changes like new props being passed in, but within the component itself, there is no way for it to know when it’s data has changed because it does not maintain its own state. For a large application, you will see significant improvements to the DOM render/update events after implementing functional components.
  • 12. When would you use functional components?
  • 13. Functional components are probably not right for most cases. After all, the point of using a JavaScript framework is to build applications which are more reactive. In Vue, you cannot do this without the reactivity system in place.
  • 14. There are, however, some excellent use cases to sprinkle in functional components: ● A component which is simply presentational. AKA, a “dumb” component. For example: buttons, pills, tags, cards, even full pages with just static text like an About page. ● A “higher order component” which is used to wrap markup or basic functionality around another component. ● Any time you find yourself in a loop (v-for), the items in the loop are usually great candidates.
  • 16. There is one small issue I’ve run into for a pretty specific use case. When using a <template> tag, and accepting data through a prop, sometimes we want to modify the data inside the template. With a standard Vue component, this is easy using either methods, or computed props. With functional components, we do not have access to methods or computed props. However, there is still a way to do this. Let’s say our component accepts a “user” prop which is an object with “firstName” and “lastName”, and we want to render a template that shows the user’s full name (let’s just assume we don’t want to simply provide a “fullName” prop”. In a functional <template> component, the way we could do this is by providing a method right on our component definition, then use the $options property provided by Vue to access our special method:
  • 17.
  • 18. Conclusion If you care about performance or ar working on very large applications, consider getting in the practice of creating functional components. The small learning curve is worth the performance gains. References: https://vuejs.org/v2/guide/render-function.html#Functional-Components https://itnext.io/whats-the-deal-with-functional-components-in-vue-js-513a31eb72b0