EmojiPicker In SPFX (ReactJS)


Emoji are ideograms and smileys used in electronic messages and web pages. Using emojis we can easily express our feelings through expressions. In this article we will learn how to implement Twitter-like emoji's in our SPFX webpart component.


Open a command prompt and create a directory for the SPFx solution.
md spfx-ReacjEmojiPicker
Navigate to the above-created directory.
cd spfx-ReacjEmojiPicker
Run the Yeoman SharePoint Generator to create the solution.
yo @microsoft/sharepoint
Solution Name
Hit Enter for the default name (spfx-ReacjEmojiPicker in this case) or type in any other name for your solution.
Selected choice - Hit Enter
Target for the component
Here, we can select the target environment where we are planning to deploy the client web part; i.e., SharePoint Online or SharePoint OnPremise (SharePoint 2016 onwards).
Selected choice - SharePoint Online only (latest).
Place of files
We may choose to use the same folder or create a subfolder for our solution.
Selected choice - same folder.
Deployment option
Selecting Y will allow the app to be deployed instantly to all sites and be accessible everywhere.
Selected choice - N (install on each site explicitly).
Permissions to access web APIs
Choose if the components in the solution require permission to access web APIs that are unique and not shared with other components in the tenant.
Selected choice - N (solution contains unique permissions)
Type of client-side component to create
We can choose to create a client-side web part or an extension. Choose the web part option.
Selected choice - WebPart
Web part name
Hit Enter to select the default name or type in any other name.
Selected choice - ReacjEmojiPicker
Web part description
Hit Enter to select the default description or type in any other value.
Framework to use
Select any JavaScript framework to develop the component. Available choices are - No JavaScript Framework, React, and Knockout.
Selected choice - React
The Yeoman generator will perform a scaffolding process to generate the solution. The scaffolding process will take a significant amount of time.
Once the scaffolding process is completed, lock down the version of project dependencies by running the below command:
npm shrinkwrap
In the command prompt, type the below command to open the solution in the code editor of your choice.
  1. npm install --save github:brianhung/emojipicker 
 in ReacjEmojiPicker.tsx
  1. import * as React from 'react';  
  2. import { IReacjEmojiPickerProps } from './IReacjEmojiPickerProps';  
  3. import './mystyle.css';  
  4. import { EmojiPicker, EmojiPickerRef} from 'react-twemoji-picker';  
  5. import {  EmojiObject} from 'react-twemoji-picker';  
  6. import * as EmojiData from "react-twemoji-picker/data/twemoji.json";  
  7. /*import  type { EmojiObject } from '../../../../node_modules/react-twemoji-picker/src/index'; 
  8. import { EmojiPicker, EmojiPickerRef  } from  '../../../../node_modules/react-twemoji-picker/src/index'; 
  9. import * as  EmojiData from "../../../../node_modules/react-twemoji-picker/data/twemoji.json";*/  
  10. const emojiData = Object.freeze(EmojiData);  
  11. const handleEmojiSelect = (emoji: EmojiObject) => console.log(emoji);  
  12. const ref = React.createRef<EmojiPickerRef>();  
  13. const handleSearch = (query: string) => ref.current.search(query);  
  14. export default class ReacjEmojiPicker extends React.Component<IReacjEmojiPickerProps, {}> {  
  15.   public render(): React.ReactElement<IReacjEmojiPickerProps> {  
  16.     console.log(EmojiData);  
  17.     return (         
  18. <>  
  19. <div style={{'display''flex''flexDirection''column''height''100vh''justifyContent''center''alignItems''center'}}>  
  20.     <h1>Emoji Picker</h1>  
  21.     <p>a virtualized <a href="https://www.c-sharpcorner.com/members/madhan-thurai/">twemoji</a> picker written in react and typescript</p>  
  22.     <EmojiPicker emojiData={emojiData['default']} handleEmojiSelect={handleEmojiSelect} ref={ref} showNavbar={true} showFooter={true}/>  
  23.     <input onChange={event => handleSearch(event.target.value)} placeholder="search"></input>  
  24.     <a href="https://twitter.com/NCMADHAN1989">Follow me on Twitter</a>  
  25.   </div>  
  26.      </>  
  27.     );  
  28.   }  
  29. }  
 in mystyle.css
  1. @import 'https://rsms.me/inter/inter.css';  
  3. html {   
  4.   font-family'Inter'sans-serif;   
  5.   font-size18px;  
  6. }  
  8. #root h1 {  
  9.   margin-bottom0;  
  10. }  
  12. #root .emoji-picker {  
  13.   margin0.5em 0;  
  14. }  
  16. #root input {  
  17.   font-size1em;  
  18.   padding0.20em 0.5em;  
  19.   margin-bottom1em;  

Settings need to change in tsconfig.json
--> add 
  1. "resolveJsonModule": true, 
The above settings will solve json loading problem in our webpart
Expected Output


In this article, we learned how to implement Twiter-like emoji components in our spfx component. I hope this helps someone. Happy coding :)