Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

React.js suneditor-react SunEditor WYSIWYG Editor to Embed Images,Text,Video & Audio in Javascript

Posted on January 23, 2023

 

 

Welcome folks today in this blog post we will be rendering the WYSIWYG editor in browser using the suneditor-react library in react.js using javascript. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make a new react.js project using the below command as shown below

 

 

npx create-react-app sampleapp

 

 

cd sampleapp

 

 

And after that you need to install the below libraries using the below command as shown below

 

 

npm i suneditor

 

 

npm i suneditor-react

 

 

And after that you will see the below directory structure of the react.js app as shown below

 

 

 

 

And now you need to go to App.js file and copy paste the following code

 

 

App.js

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
import "./styles.css";
import SunEditor from 'suneditor-react';
import 'suneditor/dist/css/suneditor.min.css';
 
export default function App() {
  return (
    <div className="App" style={{ position: "relative" }}>
      <p> My Other Contents </p>
      <SunEditor />
    </div>
  );
}

 

 

As you can see we are importing the suneditor and suneditor-react libraries at the top and then we are rendering the suneditor component. Now you will see the below result as shown below

 

 

 

 

 

Adding Custom Options to Editor

 

 

Now we will be adding some custom options to the editor as shown below

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import "./styles.css";
import SunEditor from 'suneditor-react';
import 'suneditor/dist/css/suneditor.min.css';
 
export default function App() {
  return (
    <div className="App" style={{ position: "relative" }}>
      <p> My Other Contents </p>
      <SunEditor
      lang="en"
      width="100%"
      height="100%"
      autoFocus={true}
      placeholder="Please type here..."
      />
    </div>
  );
}

 

 

As you can see we are attaching the placeholder text and also we have attached the width and height and then we are also attaching the autoFocus property to true. And default language for editor is english as shown below

 

 

 

 

 

Adding Buttons in Editor

 

 

Now we will be adding different button widgets inside the editor to add the image,audio and videos as shown below

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import "./styles.css";
import SunEditor from 'suneditor-react';
import 'suneditor/dist/css/suneditor.min.css';
 
export default function App() {
  return (
    <div className="App" style={{ position: "relative" }}>
      <p> My Other Contents </p>
      <SunEditor
      lang="en"
      width="100%"
      height="100%"
      autoFocus={true}
      placeholder="Please type here..."
      setOptions={{
        buttonList:[
          [
            "bold",
            "underline",
            "table",
            "image",
            "video",
            "audio"
          ]
        ]
      }}
      />
    </div>
  );
}

 

 

 

Recent Posts

  • Android Java Project to Capture Image From Camera & Save it in SharedPreferences & Display it in Grid Gallery
  • Android Java Project to Store,Read & Delete Data Using SharedPreferences Example
  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme