1560847110
In this tutorial, we’ll add emoji support to a chatroom built using React and Chatkit. We’ll explore two common ways of using emojis: through an emoji picker, and using the : shortcut to quickly search for and select and emoji.
Here’s a live demo of what we’ll be building:
This article builds upon what was covered in the tutorial on sending direct messages with Chatkit, so you need to go over that one first before moving on to this one. You can clone this GitHub repository and follow the instructions in the README file to get set up.
You need to have Node.js (version 8 or later) installed on your machine to be able to follow through with this tutorial. You can check out this page for instructions on how to upgrade your Node installation.
We need a few additional dependencies to build this project. react-textarea-autocomplete provides the ability to autocomplete emojis in the text input, when emoji-mart provides a beautiful emoji picker that we can take advantage of. It looks and works almost exactly like the one in Slack in case you’re wondering. Finally, we’re adding the react-feather package for icons.
Install them all by navigating to the client
directory, and running the command below:
npm install @webscopeio/react-textarea-autocomplete react-feather emoji-mart --save
Go ahead and update the styles for the app in App.css
as shown below. This is to account for the new features and components that have been added to the application.
// client/src/App.css
html {
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
h4 {
padding-left: 20px;
margin-bottom: 10px;
}
.App {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: 1fr 4fr 1fr;
}
.right-sidebar {
border-left: 1px solid #ccc;
}
.left-sidebar {
border-right: 1px solid #ccc;
}
.user-profile {
height: 70px;
display: flex;
align-items: flex-start;
padding-right: 20px;
padding-left: 20px;
justify-content: center;
flex-direction: column;
border-bottom: 1px solid #ccc;
}
.user-profile span {
display: block;
}
.user-profile .username {
font-size: 20px;
font-weight: 700;
}
.chat-rooms li, .room-member {
display: flex;
align-items: center;
padding: 15px 20px;
font-size: 18px;
color: #181919;
cursor: pointer;
border-bottom: 1px solid #eee;
margin-bottom: 0;
}
.room-member {
justify-content: space-between;
padding: 0 20px;
height: 60px;
}
.send-dm {
opacity: 0;
pointer-events: none;
font-size: 20px;
border: 1px solid #eee;
border-radius: 5px;
margin-bottom: 0;
padding: 0 10px;
line-height: 1.4;
height: auto;
}
.room-member:hover .send-dm {
opacity: 1;
pointer-events: all;
}
.presence {
display: inline-block;
width: 10px;
height: 10px;
background-color: #ccc;
margin-right: 10px;
border-radius: 50%;
}
.presence.online {
background-color: green;
}
.chat-rooms .active {
background-color: #eee;
color: #181919;
}
.chat-rooms li:hover {
background-color: #D8D1D1;
}
.room-icon {
display: inline-block;
margin-right: 10px;
}
.chat-screen {
display: flex;
flex-direction: column;
height: 100vh;
}
.chat-header {
height: 70px;
flex-shrink: 0;
border-bottom: 1px solid #ccc;
padding-left: 10px;
padding-right: 20px;
display: flex;
flex-direction: column;
justify-content: center;
}
.chat-header h3 {
margin-bottom: 0;
text-align: center;
}
.chat-messages {
flex-grow: 1;
overflow-y: auto;
display: flex;
flex-direction: column;
justify-content: flex-end;
margin-bottom: 0;
min-height: min-content;
position: relative;
}
.message {
padding-left: 20px;
padding-right: 20px;
margin-bottom: 10px;
display: flex;
justify-content: space-between;
align-items: center;
}
.message span {
display: block;
text-align: left;
}
.message .user-id {
font-weight: bold;
}
.message-form {
border-top: 1px solid #ccc;
width: 100%;
display: flex;
align-items: center;
}
.message-form, .message-input {
width: 100%;
margin-bottom: 0;
}
.rta {
flex-grow: 1;
}
.emoji-mart {
position: absolute;
bottom: 20px;
right: 10px;
}
input[type="text"].message-input, textarea.message-input {
height: 50px;
flex-grow: 1;
line-height: 35px;
padding-left: 20px;
border-radius: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border: none;
font-size: 16px;
color: #333;
min-height: auto;
overflow-y: hidden;
resize: none;
border-left: 1px solid #ccc;
}
.message-input:focus {
outline: none;
}
.toggle-emoji {
border: none;
width: 50px;
height: auto;
padding: 0;
margin-bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
.toggle-emoji svg {
width: 28px;
height: 28px;
}
/* RTA
========================================================================== */
.rta {
position: relative;
border-left: 1px solid #ccc;
display: flex;
flex-direction: column;
}
.rta__autocomplete {
position: absolute;
width: 300px;
background-color: white;
border: 1px solid #ccc;
border-radius: 5px;
}
.rta__autocomplete ul {
list-style: none;
text-align: left;
margin-bottom: 0;
}
.rta__autocomplete li {
margin-bottom: 5px;
padding: 3px 20px;
cursor: pointer;
}
.rta__autocomplete li:hover {
background-color: skyblue;
}
/* Dialog
========================================================================== */
.dialog-container {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
display: flex;
justify-content:center;
align-items: center;
}
.dialog {
width: 500px;
background-color: white;
display: flex;
align-items: center;
}
.dialog-form {
width: 100%;
margin-bottom: 0;
padding: 20px;
}
.dialog-form > * {
display: block;
}
.username-label {
text-align: left;
font-size: 16px;
}
.username-input {
width: 100%;
}
input[type="text"]:focus {
border-color: #5C8436;
}
.submit-btn {
color: #5C8436;
background-color: #181919;
width: 100%;
}
.submit-btn:hover {
color: #5C8436;
background-color: #222;
}
In any sort of non-trivial chat application, an emoji picker is an ubiquitous feature. So we’re going to start by adding the ability to input emojis into text using the emoji picker provided by emoji-mart
.
First, let’s add a button that can be used to toggle the emoji picker. Open up App.js
and change it to look like this:
// client/src/App.js
import React, { Component } from 'react';
import { Smile } from 'react-feather';
// [..]
class App extends Component {
constructor() {
super();
this.state = {
// [..]
showEmojiPicker: false,
};
// [..]
}
render() {
const {
// [..]
showEmojiPicker,
} = this.state;
return (
<div className="App">
// [..]
<section className="chat-screen">
// [..]
<footer className="chat-footer">
<form onSubmit={this.sendMessage} className="message-form">
<button
type="button"
className="toggle-emoji"
>
<Smile />
</button>
<input
type="text"
value={newMessage}
name="newMessage"
className="message-input"
placeholder="Type your message and hit ENTER to send"
onChange={this.handleInput}
/>
</form>
</footer>
</section>
// [..]
</div>
);
}
}
export default App;
The app should look like this now:
Next, let’s make the button functional by toggling the emoji picker component from emoji-mart
on click. Update the code in App.js
to look like this:
// client/src/App.js
import React, { Component } from 'react';
import { Smile } from 'react-feather';
import { Picker } from 'emoji-mart';
import {
// [..]
addEmoji,
toggleEmojiPicker,
} from './methods';
// [..]
import 'emoji-mart/css/emoji-mart.css';
// [..]
class App extends Component {
constructor() {
// [..]
this.addEmoji = addEmoji.bind(this);
this.toggleEmojiPicker = toggleEmojiPicker.bind(this);
}
render() {
const {
// [..]
} = this.state;
return (
<div className="App">
// [..]
<section className="chat-screen">
// [..]
<ul className="chat-messages">
<ChatSession messages={messages} />
{showEmojiPicker ? (
<Picker set="emojione" onSelect={this.addEmoji} />
) : null}
</ul>
<footer className="chat-footer">
<form onSubmit={this.sendMessage} className="message-form">
<button
type="button"
className="toggle-emoji"
onClick={this.toggleEmojiPicker}
>
<Smile />
</button>
<input
type="text"
value={newMessage}
name="newMessage"
className="message-input"
placeholder="Type your message and hit ENTER to send"
onChange={this.handleInput}
/>
</form>
</footer>
</section>
// [..]
</div>
);
}
}
export default App;
Then update the methods.js
file with the following new functions:
// client/src/methods.js
import Chatkit from '@pusher/chatkit-client';
import axios from 'axios';
function toggleEmojiPicker() {
this.setState({
showEmojiPicker: !this.state.showEmojiPicker,
});
}
function addEmoji(emoji) {
const { newMessage } = this.state;
const text = `${newMessage}${emoji.native}`;
this.setState({
newMessage: text,
showEmojiPicker: false,
});
}
// [..]
export { sendMessage, handleInput, connectToRoom, connectToChatkit, sendDM, toggleEmojiPicker, addEmoji };
The toggleEmojiPicker()
method shows and hides the emoji picker component, while addEmoji()
updates the message input with the selected emoji. You can try it out by selecting an emoji from the emoji picker. It should work as shown below:
An added way to quickly input emoji in a message is by triggering autocomplete by typing :
, followed by the first few letters and a menu will appear where you can select the emoji you want to use. We’ll implement this functionality in our application using react-textarea-autocomplete. Make the following changes in App.js
:
// client/src/App.js
import React, { Component } from 'react';
import { Picker, emojiIndex } from 'emoji-mart';
import { Smile } from 'react-feather';
import ReactTextareaAutocomplete from '@webscopeio/react-textarea-autocomplete';
import {
// [..]
handleKeyPress,
} from './methods';
// [..]
class App extends Component {
constructor() {
// [..]
this.handleKeyPress = handleKeyPress.bind(this);
}
render() {
// [..]
return (
<div className="App">
// [..]
<section className="chat-screen">
// [..]
<footer className="chat-footer">
<form onSubmit={this.sendMessage} className="message-form">
<button
type="button"
className="toggle-emoji"
onClick={this.toggleEmojiPicker}
>
<Smile />
</button>
<ReactTextareaAutocomplete
className="message-input my-textarea"
name="newMessage"
value={newMessage}
loadingComponent={() => <span>Loading</span>}
onKeyPress={this.handleKeyPress}
onChange={this.handleInput}
placeholder="Compose your message and hit ENTER to send"
trigger={{
':': {
dataProvider: token =>
emojiIndex.search(token).map(o => ({
colons: o.colons,
native: o.native,
})),
component: ({ entity: { native, colons } }) => (
<div>{`${colons} ${native}`}</div>
),
output: item => `${item.native}`,
},
}}
/>
</form>
</footer>
</section>
// [..]
</div>
);
}
}
export default App;
Then, update methods.js
with the new handleKeyPress()
method and update the sendMessage()
method:
// client/src/methods.js
import Chatkit from '@pusher/chatkit-client';
import axios from 'axios';
function handleKeyPress(event) {
if (event.key === 'Enter') {
event.preventDefault();
this.sendMessage();
}
}
// [..]
function sendMessage() {
const { newMessage, currentUser, currentRoom } = this.state;
if (newMessage.trim() === '') return;
currentUser.sendMessage({
text: newMessage,
roomId: `${currentRoom.id}`,
});
this.setState({
newMessage: '',
});
}
export { sendMessage, handleInput, connectToRoom, connectToChatkit, sendDM, toggleEmojiPicker, addEmoji, handleKeyPress };
In ReactTextareaAutocomplete
, the dataProvider
is called after each keystroke to get an array of what the suggestion list should display, and component
is the component for rendering the item in suggestion list. Finally, the output
defines text which will be placed into text area after the user makes a selection.
Try it out by typing :
, followed by the first few letters of the emoji you want to input. It should display a few suggestions and you can click on anyone of them to make your selection.
In this tutorial, we learned how to jazz up your React-based chatroom with emoji support. We covered how to use add an emoji picker component, and also how to trigger emoji suggestions using the :
shortcut.
You can checkout other things Chatkit can do by viewing its extensive documentation. Don’t forget to grab the full source code used in this tutorial in this GitHub repository.
#reactjs
1598839687
If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?
In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.
Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.
React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.
Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.
Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.
The popularity of React Native comes from its advantages. Some of its advantages are as follows:
Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.
React Native is very close to native. Consider the following aspects as described on the React Native website:
Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.
#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native
1615544450
Since March 2020 reached 556 million monthly downloads have increased, It shows that React JS has been steadily growing. React.js also provides a desirable amount of pliancy and efficiency for developing innovative solutions with interactive user interfaces. It’s no surprise that an increasing number of businesses are adopting this technology. How do you select and recruit React.js developers who will propel your project forward? How much does a React developer make? We’ll bring you here all the details you need.
Facebook built and maintains React.js, an open-source JavaScript library for designing development tools. React.js is used to create single-page applications (SPAs) that can be used in conjunction with React Native to develop native cross-platform apps.
In the United States, the average React developer salary is $94,205 a year, or $30-$48 per hour, This is one of the highest among JavaScript developers. The starting salary for junior React.js developers is $60,510 per year, rising to $112,480 for senior roles.
In context of software developer wage rates, the United States continues to lead. In high-tech cities like San Francisco and New York, average React developer salaries will hit $98K and $114per year, overall.
However, the need for React.js and React Native developer is outpacing local labour markets. As a result, many businesses have difficulty locating and recruiting them locally.
It’s no surprise that for US and European companies looking for professional and budget engineers, offshore regions like India are becoming especially interesting. This area has a large number of app development companies, a good rate with quality, and a good pool of React.js front-end developers.
As per Linkedin, the country’s IT industry employs over a million React specialists. Furthermore, for the same or less money than hiring a React.js programmer locally, you may recruit someone with much expertise and a broader technical stack.
React is a very strong framework. React.js makes use of a powerful synchronization method known as Virtual DOM, which compares the current page architecture to the expected page architecture and updates the appropriate components as long as the user input.
React is scalable. it utilises a single language, For server-client side, and mobile platform.
React is steady.React.js is completely adaptable, which means it seldom, if ever, updates the user interface. This enables legacy projects to be updated to the most new edition of React.js without having to change the codebase or make a few small changes.
React is adaptable. It can be conveniently paired with various state administrators (e.g., Redux, Flux, Alt or Reflux) and can be used to implement a number of architectural patterns.
Is there a market for React.js programmers?
The need for React.js developers is rising at an unparalleled rate. React.js is currently used by over one million websites around the world. React is used by Fortune 400+ businesses and popular companies such as Facebook, Twitter, Glassdoor and Cloudflare.
As you’ve seen, locating and Hire React js Developer and Hire React Native developer is a difficult challenge. You will have less challenges selecting the correct fit for your projects if you identify growing offshore locations (e.g. India) and take into consideration the details above.
If you want to make this process easier, You can visit our website for more, or else to write a email, we’ll help you to finding top rated React.js and React Native developers easier and with strives to create this operation
#hire-react-js-developer #hire-react-native-developer #react #react-native #react-js #hire-react-js-programmer
1607768450
In this article, you will learn what are hooks in React JS? and when to use react hooks? React JS is developed by Facebook in the year 2013. There are many students and the new developers who have confusion between react and hooks in react. Well, it is not different, react is a programming language and hooks is a function which is used in react programming language.
Read More:- https://infoatone.com/what-are-hooks-in-react-js/
#react #hooks in react #react hooks example #react js projects for beginners #what are hooks in react js? #when to use react hooks
1627031571
The most awaited version of React 18 is finally out now. Its team has finally revealed the alpha version of React 18 and its plan, though the official launch is still pending. This time the team has tried something and released the plan first to know their user feedback because the last version of React 17 was not that much appreciated among developers.
According to Front-end Frameworks Survey, React JS has ranked top in the list of most loved frameworks. Thus, the developer communities expect a bit higher from the framework, so they are less appreciative of the previous launch.So, this time React 18 will be a blast. For beginners, the team is working on a new approach. They have called a panel of experts, library authors, educators, and developers to take part in a working group. Initially, it will be a small group.
I am not a part of this release but following the team on their GitHub discussion group. After gathering the information from there, I can say that they have planned much better this time.
React 17 was not able to meet the developer's community. The focus was all primarily centered on making it easier to upgrade React itself. React 18 release will be the opposite. It has a lot of features for react developers.
#hire react js developers #hire react js developers india #react developers india #react js developer #react developer #hire react developers
1589722410
As we start learning new technologies we want to start building something or work on a simple project to get a better understanding of the technology. So, let’s build this simple app.
For this app, we will be using PokeApi to get our pokemon data, and also we will be using Hooks. I am using pokemondb for pokemon sprites. It’s just a personal preference you can use whatever you want.
#react-native #react-native-app #react-navigation #react-native-development #react