New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-safe

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-safe

Safe JSX: syntactic sugar over dangerouslySetInnerHTML

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

React Safe

This package provides a syntactic sugar over the raw dangerousSetInnerHTML.

Motivation

In real projects, at least in my experience, the usage of dangerousSetInnerHTML is extensive. Which brings two problems:

  • It's too long and ugly for its frequency. Also JSX does not look like HTML anymore as tag contents are passed via attributes. Which kinda defeats the usage point of JSX.

  • The term "dangerous" is misleading. It represents something a programmer considers safe(!) instead. So it kinda spams the vision with irrelevant signals of false danger decreasing the capability to notice real threats.

Examples

React (vanilla)

<h1 dangerouslySetInnerHTML={{__html: page.title}}></h1>
<div dangerouslySetInnerHTML={{__html: renderMD(page.body)}}></div>

React Safe

<Safe.h1>{page.title}</Safe.h1>
<Safe.div>{renderMD(page.body)}</Safe.div>

License

MIT

Keywords

react

FAQs

Package last updated on 20 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts