block-content-to-react
sanity
Our great sponsors
block-content-to-react | sanity | |
---|---|---|
2 | 93 | |
161 | 4,899 | |
- | 1.6% | |
0.0 | 10.0 | |
about 1 year ago | 4 days ago | |
JavaScript | TypeScript | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
block-content-to-react
-
Anchor Links From Sanity in Gatsby
This is a simple react component that uses @sanity/block-content-to-react. The great part here is that they have allowed for serializers and you can add a great deal of customization to any of the block based PortableText that you will be receiving from the graphql from Sanity.io.
-
Make a Progressive Web App with React
// /src/MadLib.js import { useQuery } from 'react-query'; import { useParams, Link } from 'react-router-dom'; import { useState, useEffect } from 'react'; import BlockContent from '@sanity/block-content-to-react'; import { sanity, imageUrlBuilder } from './sanity'; import styles from './MadLib.module.css'; const query = ` *[ _type == 'madLib' && slug.current == $slug ] `; function MadLib() { // this variable is populated from `react-router` which pulls it from the URL const { slug } = useParams(); // data is fetched from sanity via the sanity client and stored into // application state via react-query. note that the slug is used as the // "query key": https://react-query.tanstack.com/guides/query-keys const { data = [] } = useQuery(slug, () => sanity.fetch(query, { slug })); // we'll use destructuring assignment to return the first mab lib const [madLib] = data; // this will store the state of the answers of this mad lib const [answers, setAnswers] = useState( // if the items exist in localStorage, then localStorage.getItem(slug) ? // then set the initial state to that value JSON.parse(localStorage.getItem(slug)) : // otherwise, set the initial state to an empty object {}, ); // this is a react "effect" hook: https://reactjs.org/docs/hooks-effect.html // we use this to watch for changes in the `slug` or `answers` variables and // update local storage when those change. useEffect(() => { localStorage.setItem(slug, JSON.stringify(answers)); }, [slug, answers]); if (!madLib) { return
Loading…h1>; } // once the mad lib is loaded, we can map through the structured content to // find our placeholder shape. the end result is an array of these placeholders const placeholders = madLib?.story .map((block) => block.children.filter((n) => n._type === 'placeholder')) .flat(); // using the above placeholders array, we calculate whether or not all the // blanks are filled in by checking the whether every placeholder has a value // in the `answers` state variable. const allBlanksFilledIn = placeholders?.every( (placeholder) => answers[placeholder._key], ); return ( <>
{madLib.title}h2> {!allBlanksFilledIn ? ( // if all the blanks are _not_ filled in, then we can show the form <>
Fill in the blank!p>
When you're done, the finished mad lib will appear.p>
{ e.preventDefault(); const answerEntries = Array.from( // find all the inputs e.currentTarget.querySelectorAll('input'), ) // then get the name and values in a tuple .map((inputEl) => [inputEl.name, inputEl.value]); // use `Object.fromEntries` to transform them back to an object const nextAnswers = Object.fromEntries(answerEntries); setAnswers(nextAnswers); }} >-
{/* for each placeholder… */}
{placeholders.map(({ _key, type }) => (
- {/* …render an input an a label. */} {type} label> li> ))} ul> Submit!button> form> ) : ( // if all the blanks are filled in, then we can show the rendered // story with a custom serializer for the type `placeholder` <> answers[_key] }, }} /> { // we reset the state on click after the users confirms it's okay. if (window.confirm('Are you sure you want to reset?')) { setAnswers({}); } }} > Reset button> {/* this is a simple link back to the main mab libs index */} ← More Mad Libs Link> )} ); } export default MadLib;
sanity
- Ask HN: Freelance website builders/maintainers, what's in your 2024 toolkit?
-
Breaking Down Next.js 14
For Sanity users:
-
How to Deploy your fullstack website - My approach
Sanity is a flexible and customizable headless content management system (CMS) designed to empower developers and content creators to build digital experiences. It has a free plan which includes a hosted, real-time content database which means you don’t have to go through the stress of looking for a backend service to deploy your backend Api.
-
A list of SaaS, PaaS and IaaS offerings that have free tiers of interest to devops and infradev
Sanity.io - Platform for structured content with an open-source editing environment and a real-time hosted data store. Unlimited projects. Unlimited admin users, three non-admin users, two datasets, 500K API CDN requests, 10GB bandwidth, and 5GB assets included for free per project.
-
Integrating Sanity's Presentation Tool with Next.js: Comprehensive Guide
The world of web development is constantly evolving, with new tools and technologies emerging to optimize the content creation and management process. One such tool is the Sanity Presentation Tool, a powerful feature within the Sanity.io ecosystem designed to enhance the content editing experience. This tool bridges the gap between content management and frontend presentation, offering a seamless, real-time editing interface that is invaluable for content creators and developers alike.
-
Curious what you guys think of my company's "incentivized unlimited PTO" program.
Her new job states everyone gets 5 weeks of vacation per year. And they MUST take at least 4 weeks each year. www.sanity.io
-
Best website builder for a news website
https://strapi.io/ https://prismic.io/ https://bubble.io/ https://hygraph.com/ https://www.sanity.io/
-
Different flavors of content management
A headless one is responsible only for data management and providing an API for other applications to show this data. When talking about headless CMS, Strapi or Sanity comes to my mind first, but there are many more.
-
Can a CMS be connected to a static HTML/CSS website?
You could check out Storyblok, they have a nice free tier (most headless CMSes do) so you wouldn't have to pay for hosting. Some other good options are Prismic and Sanity Sanity.
-
Best way to keep a site up to date!
I recently started a project using sanity as a headless cms, and it was pretty easy to set up. Looking at the pricing, you might even be able to stay on the free tier for this site.
What are some alternatives?
fill-in-the-blank - This is for an article i'm writing.
Strapi - 🚀 Strapi is the leading open-source headless CMS. It’s 100% JavaScript/TypeScript, fully customizable and developer-first.
React-Commenting-System - Commenting System built with NextJS and Sanity
decap-cms - A Git-based CMS for Static Site Generators
pxi - 🧚 pxi (pixie) is a small, fast, and magical command-line data processor similar to jq, mlr, and awk.
KeystoneJS - The most powerful headless CMS for Node.js — built with GraphQL and React
portabletext - Portable Text is a JSON based rich text specification for modern content editing platforms.
Directus - The Modern Data Stack 🐰 — Directus is an instant REST+GraphQL API and intuitive no-code data collaboration app for any SQL database.
HULL - 💀 Headless Shopify Starter – powered by Next.js + Sanity.io
redux - A JS library for predictable global state management
firecms - Awesome Firebase/Firestore-based CMS. The missing admin panel for your Firebase project!
MongoDB - The MongoDB Database