• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

How can i solve the problem from the book road to react at page 78 ? I keep getting undefine for one of the methods in the table component

April 11, 2020 by

Questions › How can i solve the problem from the book road to react at page 78 ? I keep getting undefine for one of the methods in the table component
0
Vote Up
Vote Down
Garmaine asked 3 years ago
import React, { Component } from 'react';
  import './App.css';

  const list = [
    {
      title: 'React',
      url: 'https://facebook.github.io/react/',
      author: 'Jordan Walke',
      num_comments: 3,
      points: 4,
      objectID: 0,
    },
    {
      title: 'Redux',
      url: 'https://github.com/reactjs/redux',
      author: 'Dan Abramov, Andrew Clark',
      num_comments: 2,
      points: 5,
      objectID: 1,
    },
  ];

  class App extends Component {


    state = {
      list,
      text: 'abc',
      searchTerm: ''
    }



    onDisMiss = (id) => {
      const updateList = this.state.list.filter((item) => item.objectID != id)
      return () => this.setState({ list: updateList })
    }

    onSearchChange = (event) => {
      this.setState({ searchTerm: event.target.value })
    }

    isSearched = (searchTerm) => {
      return (item) => item.title.toLowerCase().includes(searchTerm.toLowerCase())
    }

    render() {
      const { searchTerm, list } = this.state
      return (
        <div>
          <Search value={searchTerm}
            onChange={this.onSearchChange}>Search</Search>
          <Table list={list} pattern={searchTerm} onDissMiss={this.onDisMiss} />
        </div>
      );
    }
  }


  class Search extends Component {
    render() {
      const { value, onChange, children } = this.props
      return (
        <div>
          <form>
            {children}<input type="text" onChange={onChange} value={value} />
          </form>
        </div>
      );
    }
  }


  class Table extends Component {

    render() {
      const { list, pattern, onDisMiss } = this.props
      return (
        <div>
          {list.filter(isSearched(pattern)).map(item =>
            <div key={item.objectID}>
              <span><a href={item.url}>{item.title}</a></span>
              <span>{item.author}</span>
              <span>{item.num_comments}</span>
              <span>{item.points}</span>

              <span>
                <button onClick={onDisMiss(item.objectID)} type="button">Dismiss</button>
              </span>

            </div>)
          }
        </div>
      );
    }
  }
  export default App;

Road to react Book The Table component related.I get undefined for the isSearched method. how can I fix it so it works correctly its from the book road to react it seems like the book has a few error which I have problems solving because am just learning react. can you help with the solution and why this problem is actually happening

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: javascript, reactjs

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Copyright © 2023