Advertisement
fakesamgregory

Master React in Webflow - Components

Nov 6th, 2024 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.js
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';
  4.  
  5. import App from './App';
  6.  
  7. const element = document.getElementsByClassName('react')[0];
  8. const root = ReactDOM.createRoot(element);
  9. root.render(<App />);
  10.  
  11. /* ------------ */
  12. // App.js
  13. import React from 'react';
  14. import HeadingOne from './HeadingOne';
  15. import List from './List';
  16.  
  17. export default function App() {
  18.     const list = [
  19.         { text: "hello" }
  20.         { text: "goodbye" }
  21.         { text: "wombats" }
  22.     ];
  23.  
  24.     return (
  25.         <>
  26.             <HeadingOne text="Hello Wombats!" />
  27.             <List list={list} />
  28.         </>
  29.     );
  30. }
  31.  
  32. /* ------------ */
  33. // HeadingOne.js
  34. import React from 'react';
  35.  
  36. export default function HeadingOne({ text = "Hello world" }) {
  37.     return <h1>{text}</h1>
  38. }
  39.  
  40. /* ------------ */
  41. // List.js
  42. import React from 'react';
  43.  
  44. export default function List({ list = [] }) {
  45.     return (
  46.         <ul>
  47.             {list.map(listItem => <li>{listItem.text}</li>}
  48.         </ul>
  49.     );
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement