GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - scratchblocks/scratchblocks-react: Render scratchblocks in React!

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
types/scratchblocks
types/scratchblocks
 
 
.gitignore
.gitignore
 
 
.prettierrc
.prettierrc
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

scratchblocks-react

Render scratchblocks in React!

Installation

npm install scratchblocks scratchblocks-react
# or
yarn add scratchblocks scratchblocks-react

Note that in addition to the scratchblocks-react package, you must have scratchblocks installed (and react).

Usage

Simple

import ScratchBlocks from "scratchblocks-react"

function MyComponent() {
  return (
    <ScratchBlocks blockStyle="scratch3">
      {`
        when green flag clicked
        forever
          move (10) steps
        end
      `}
    </ScratchBlocks>
  )
}

Dynamic

In this example, the user can edit the Scratch code.

import ScratchBlocks from "scratchblocks-react"

function MyComponent() {
  const [code, setCode] = useState("move (10) steps")

  return (
    <div>
      <textarea
        value={code}
        onChange={(event) => setCode(event.target.value)}
      />
      <ScratchBlocks blockStyle="scratch3">{code}</ScratchBlocks>
    </div>
  )
}

Non-English Languages

import ScratchBlocks from "scratchblocks-react"

// Load some extra languages (English comes loaded by default)
import scratchblocks from "scratchblocks"
import es from "scratchblocks/locales/es.json" // Spanish
import de from "scratchblocks/locales/de.json" // German

// Register the language files with scratchblocks
scratchblocks.loadLanguages({ es, de })

function MyComponent() {
  return (
    <ScratchBlocks
      blockStyle="scratch3"
      languages={["en", "es", "de"]} // Choose which languages to allow
    >
      {`
        when green flag clicked
        por siempre
          gehe (10) er Schritt
        fin
      `}
    </ScratchBlocks>
  )
}

Available Props

Name Default Valid Values Description
blockStyle "scratch2" "scratch2" or "scratch3" Changes the visual style of the rendered blocks.
languages ["en"] An array of language codes such as ["en", "de"] Enables the use of non-english languages. Requires additional setup.
... and more! All other props (such as "className" and "style") will be passed directly to the div.

About

Render scratchblocks in React!

Resources

Readme
Activity
Custom properties

Stars

7 stars

Watchers

1 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.