Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ambar/react-element
https://github.com/ambar/react-element
cloneelement createelement react
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ambar/react-element
- Owner: ambar
- Created: 2017-01-13T12:37:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T17:52:36.000Z (about 2 years ago)
- Last Synced: 2024-04-26T11:20:15.263Z (10 months ago)
- Topics: cloneelement, createelement, react
- Language: JavaScript
- Size: 1.78 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 元素替换
合并 createElement 与 cloneElement 的使用 😉
[![build status](https://badgen.net/travis/ambar/react-element)](https://travis-ci.org/ambar/react-element)
[![npm version](https://badgen.net/npm/v/react-element)](https://www.npmjs.com/package/react-element)
[![minzipped size](https://badgen.net/bundlephobia/minzip/react-element)](https://bundlephobia.com/result?p=react-element)## 基本用法
```js
import Element from 'react-element'// 标签替换
text
// 构造函数替换
text
// 实例替换
}>text
```## 其他用例
### 一、防止意外属性传递到 DOM 元素
如防止 `to` 在条件不成立时到传递到 `div` 标签上:
```js
: 'div'}
>
Live```
### 二、多个组件共用相同 DOM 元素
如一个组件有 Item > ItemInner 两层结构,Item + Item 有并列样式,ItemInner 有 `padding`,需要替换外层的元素为链接时。