In search for a minimal store for React applications.
I have been depending on Context for passing state through components in React and eventually thinks complicated when data is become complex. Move on to beautiful Redux is a bit expensive.
For learning Redux I have spent lots of time and Redux Toolkit, easy to use Redux, saved me a lot.
Even though RTK is ok, it is not a simple library. I am fan of Svelte store and Vuex, Pinia store. Is there any such library for React?
I recently found Zustand a minimal store for React. Love it. 😍
We nee a set of pages and dynamic route for posts and category posts. In Nextjs we can easily setup pages/route under pages directory.
404
The 404 page can be setup as a route that match all, any non existing route/page.
Under the page directory create […].js with default export
import React from 'react'
import PNF from '../Components/PNF'
export default function ErrorPage() {
return (
<PNF/>
)
}
Here PNF is beautiful animated PageNotFound component, we just created in the component directory.
Using useRouter/next/router, we can access the params of dynamic route.
Dynamic route
Layout
Our blog uses single layout, so we go with a Layout component which define Navbar and footer and a content area and implement the layout in the _app.js as follows.
We have already covered post regarding Quilljs RichText Editor, configuration and advanced use as well. Now time to get some more feature. This time add some 🥤 to it, the mention.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How fix double instance issue in react-editor-js block editor toolkit
React-Editor-js is a toolkit for react which implement the Editorjs,block editor in React application.
The Bugg🐛
When you trying to implement the toolkitinto a modern React application you may got double instance of the Editor 👇. I don’t know why it is happening, 😔.
Fix
The problem her is not with the versions but the react-dom/client(🤔). My regular index.js look like this.
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
reportWebVitals();
To fix our current issue I replace index.js as following with ReactDom.render method and the problem will melt away. 😊
import ReactDOM from "react-dom";
import React from "react";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reportWebVitals();
If anybody have a better solution for this, please leave in the comment section.
React-quill is a toolkit for react which implement the Quilljs editor in react application.
When you trying to implement the react-quill into a modern React application you may got double instance of the Editor 👇. I don’t know why it is happening, 😔.
Fix
The problem her is not with the versions but the react-dom/client(🤔). My regular index.js look like this.
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
reportWebVitals();
To fix our current issue I replace index.js as following with ReactDom.render method and the problem will melt away. 😊
import ReactDOM from "react-dom";
import React from "react";
import App from "./App";
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
reportWebVitals();
If anybody have a better solution for this, please leave in the comment section.
How to create a minimal editor in React using Tiptap
Tiptap is a modern Editor framework for Javascript applications. It is popular because come with bunch pro features, extension, flexibility and its well documented for all frameworks such as Nextjs, Vuejs, React etc.
There are 50 more extensions ready to boost editor experience.
Let’s setup our react project with Tiptap dependencies.
We can use hooks to create our Tiptap component in React.
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import './styles.css'
export default function Minimal () {
const editor = useEditor({
extensions: [
Document,
Paragraph,
Text,
],
content: `
<p>
This is a radically reduced version of tiptap. It has support for a document, with paragraphs and text. That’s it. It’s probably too much for real minimalists though.
</p>
<p>
The paragraph extension is not really required, but you need at least one node. Sure, that node can be something different.
</p>
`,
})
return (
<EditorContent editor={editor} />
)
}
If you are building content based application such as blog, may want featured editor, such as Post editor or comment box. Making such an editor with all formatting capabilities would be tiresome.
Editor frameworks and wrapper libraries help us achieve this goal with ease and peace. I don’t intended to review each of these , instead I would to list best of them and in the up coming posts we will learn using these awesome editor frameworks.
My Picks
I like block editor mostly for content management, in my react app I will choose the Editor.js . It is easy to configure and use.
Second most useful framework for content management is Drftjs , which is maintained by Facebook itself. It is a complete Editor framework featuring mention, hashtag etc and it’s flexible too.
Here is complete list of framework available for building a full featured editor in your next JS / React/Vue/Angular app