react-peek
Gather data by inspecting react components
A drop-in replacement for Facebook's prop-types with added properties on the resolver functions that store prop type data.
Install
npm i --save react-peek
Usage
Define propTypes for your component.
; const propTypes = className: PropTypesstring size: PropTypesisRequired onClick: PropTypesfunc` Callback function triggered when user clicks on the button. `;
then inspect the peek
property to get info about a particular propType.
propTypesclassNamepeektype; // 'string'propTypessizepeektype; // 'oneOf'propTypessizepeekisRequired; // truepropTypessizepeekargs; // ['large', 'small']propTypesonClickpeektype; // 'func'propTypesonClickpeektext; // '\n Callback function triggered when user clicks on the button.\n '
Optimizing builds
Template strings can be removed in production builds by using the babel plugin react-peek/babel
.
Example .babelrc
:
This will replace this:
className: PropTypesstring` Passes a custom className through to the component. ` size: PropTypesisRequired` Sets the size of the button. ` onClick: PropTypesfunc` Callback function triggered when user clicks on the button. `;
with this:
className: PropTypesstring size: PropTypesisRequired onClick: PropTypesfunc;