DevDino 🦖

我曾七次鄙视自己的灵魂

React.memo

react.memo 有第二个参数,可以通过第二个参数来自定义组件的渲染时机。

阅读全文 »

当多种 children 一起输入时

function Container(props) {
const defaultProps = {
name: "alen",
msg: "hello",
}

return props.children.map((item) => {
// 通过判断 clone 混入props
if (React.isValidElement(item)) {
return React.cloneElement(item, { ...defaultProps })
} else if (typeof item === "function") {
return item(defaultProps)
} else {
return null
}
})
}

function Child(props) {
return <div>{props.name + props.msg} </div>
}

function App() {
return (
<Container>
// 多种方式混入
<Child />
{(props) => <Child {...props} />}
</Container>
)
}

render(<App />, document.getElementById("root"))
阅读全文 »

createObjectURL 是什么

URL.createObjectURL() 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的 URL。这个 URL 的生命周期和创建它的窗口中的 document 绑定。这个新的 URL 对象表示指定的 File 对象或 Blob 对象。 — MDN

阅读全文 »

原型与原型链

实例与构造函数原型之间有直接的联系,但实例与构造函数之间没有。

阅读全文 »