0.0.1 • Published 6 years ago
set-prop-types v0.0.1
setPropTypes()
Overview
Provides a convenient syntax to set prop types and default props on a React component:
setPropTypes(Component, callback)
Set a default prop by, instead of just a prop type, providing an array with both the prop type and the default prop:
See prop-types for more info.
Example
import React from 'react'
import setPropTypes from 'set-prop-types'
export default function App () {
return <>
<Greeter name="Jimmy" rating={100} />
<Greeter name="Johnny" rating="S++" />
</>
}
function Greeter ({name, rating, line}) {
return <>
<h3>Hey, {name}!</h3>
<p>Your rating is {rating}.</p>
{line ? <hr /> : null}
</>
}
setPropTypes(Greeter, T => ({
name: T.string,
rating: T.oneOfType([T.string, T.number]),
line: [T.bool, true]
}))
0.0.1
6 years ago