Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to map elements from 1st object react js

function Blog(props) {
  const sidebar = (
    <ul>
      {props.posts.map((post) =>
        <li key={post.id}>
          {post.title}
        </li>
      )}
    </ul>
  );
  const content = props.posts.map((post) =>
    <div key={post.id}>
      <h3>{post.title}</h3>
      <p>{post.content}</p>
    </div>
  );
  return (
    <div>
      {sidebar}
      <hr />
      {content}
    </div>
  );
}

const posts = [
  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
  {id: 2, title: 'Installation', content: 'You can install React from npm.'}
];

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Blog posts={posts} />);
Comment

how to map elements from 1st object react js

function Blog(props) {
  const sidebar = (
    <ul>
      {props.posts.map((post) =>
        <li key={post.id}>
          {post.title}
        </li>
      )}
    </ul>
  );
  const content = props.posts.map((post) =>
    <div key={post.id}>
      <h3>{post.title}</h3>
      <p>{post.content}</p>
    </div>
  );
  return (
    <div>
      {sidebar}
      <hr />
      {content}
    </div>
  );
}

const posts = [
  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
  {id: 2, title: 'Installation', content: 'You can install React from npm.'}
];

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Blog posts={posts} />);
Comment

how to map elements from 1st object react js

function Blog(props) {
  const sidebar = (
    <ul>
      {props.posts.map((post) =>
        <li key={post.id}>
          {post.title}
        </li>
      )}
    </ul>
  );
  const content = props.posts.map((post) =>
    <div key={post.id}>
      <h3>{post.title}</h3>
      <p>{post.content}</p>
    </div>
  );
  return (
    <div>
      {sidebar}
      <hr />
      {content}
    </div>
  );
}

const posts = [
  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
  {id: 2, title: 'Installation', content: 'You can install React from npm.'}
];

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Blog posts={posts} />);
Comment

PREVIOUS NEXT
Code Example
Javascript :: check letter case 
Javascript :: get random hsl color js 
Javascript :: check notification permissopn allow or not 
Javascript :: show json preformatted 
Javascript :: nextjs check path 404 
Javascript :: prevent alpine js from rendering components during refresh 
Javascript :: nestjs TS2339 
Javascript :: vue mount modal to body 
Javascript :: Adding A Function To All Node Example With Javascript 
Javascript :: convert javascript to python 
Javascript :: js function expression 
Javascript :: js object filter by keys 
Javascript :: how to call function from another component in vue js 
Javascript :: react time picker 
Javascript :: if else javascript 
Javascript :: find an object in an array by one of its properties 
Javascript :: date pipe 
Javascript :: how to do subtraction in javascript 
Javascript :: map && arrow function in javascript 
Javascript :: uncaught typeerror e.indexof is not a function jquery load 
Javascript :: function in javascript 
Javascript :: sub function javascript 
Javascript :: hrtime to milliseconds 
Javascript :: discord.js lock channel 
Javascript :: add multiple images inside the DOM js 
Javascript :: calculate days between two dates in javascript 
Javascript :: break loop timeout javascript 
Javascript :: how to declare objects inside arrays in javascript 
Javascript :: npm passport-instagram 
Javascript :: create immutable object in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =