Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # `react-is`
  2. This package allows you to test arbitrary values and see if they're a particular React element type.
  3. ## Installation
  4. ```sh
  5. # Yarn
  6. yarn add react-is
  7. # NPM
  8. npm install react-is
  9. ```
  10. ## Usage
  11. ### Determining if a Component is Valid
  12. ```js
  13. import React from "react";
  14. import * as ReactIs from "react-is";
  15. class ClassComponent extends React.Component {
  16. render() {
  17. return React.createElement("div");
  18. }
  19. }
  20. const FunctionComponent = () => React.createElement("div");
  21. const ForwardRefComponent = React.forwardRef((props, ref) =>
  22. React.createElement(Component, { forwardedRef: ref, ...props })
  23. );
  24. const Context = React.createContext(false);
  25. ReactIs.isValidElementType("div"); // true
  26. ReactIs.isValidElementType(ClassComponent); // true
  27. ReactIs.isValidElementType(FunctionComponent); // true
  28. ReactIs.isValidElementType(ForwardRefComponent); // true
  29. ReactIs.isValidElementType(Context.Provider); // true
  30. ReactIs.isValidElementType(Context.Consumer); // true
  31. ReactIs.isValidElementType(React.createFactory("div")); // true
  32. ```
  33. ### Determining an Element's Type
  34. #### Context
  35. ```js
  36. import React from "react";
  37. import * as ReactIs from 'react-is';
  38. const ThemeContext = React.createContext("blue");
  39. ReactIs.isContextConsumer(<ThemeContext.Consumer />); // true
  40. ReactIs.isContextProvider(<ThemeContext.Provider />); // true
  41. ReactIs.typeOf(<ThemeContext.Provider />) === ReactIs.ContextProvider; // true
  42. ReactIs.typeOf(<ThemeContext.Consumer />) === ReactIs.ContextConsumer; // true
  43. ```
  44. #### Element
  45. ```js
  46. import React from "react";
  47. import * as ReactIs from 'react-is';
  48. ReactIs.isElement(<div />); // true
  49. ReactIs.typeOf(<div />) === ReactIs.Element; // true
  50. ```
  51. #### Fragment
  52. ```js
  53. import React from "react";
  54. import * as ReactIs from 'react-is';
  55. ReactIs.isFragment(<></>); // true
  56. ReactIs.typeOf(<></>) === ReactIs.Fragment; // true
  57. ```
  58. #### Portal
  59. ```js
  60. import React from "react";
  61. import ReactDOM from "react-dom";
  62. import * as ReactIs from 'react-is';
  63. const div = document.createElement("div");
  64. const portal = ReactDOM.createPortal(<div />, div);
  65. ReactIs.isPortal(portal); // true
  66. ReactIs.typeOf(portal) === ReactIs.Portal; // true
  67. ```
  68. #### StrictMode
  69. ```js
  70. import React from "react";
  71. import * as ReactIs from 'react-is';
  72. ReactIs.isStrictMode(<React.StrictMode />); // true
  73. ReactIs.typeOf(<React.StrictMode />) === ReactIs.StrictMode; // true
  74. ```