_this2.props.moveShelf is not a function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am learning React.
I am working on a Myreads book app project. My app renders fine at the start but the moment I click on the select tag, i get the above error message thrown up.
I thought it was a 'propTypes' issue at first and went ahead and installed prop-types
but it is still not working.
Here is my cmp where there error occurs and my parent cmp where my method is defined:
// child component
import React from "react";
import Icon from "./icons/add.svg";
import SearchBar from "./SearchBar";
class Book extends React.Component {
render() {
return (
<div className="book">
<div className="book-top">
<div
className="book-cover"
style={{
width: 128,
height: 193,
backgroundImage: `${
this.props.book.imageLinks
? "url(this.props.book.imageLinks.thumbnail)"
: "Icon"
}`
}}
/>
<div className="book-shelf-changer">
<select
onChange={event =>
this.props.moveShelf(this.props.book, event.target.value)
}
value={this.props.book.shelf}
>
<option value="move" disabled>
Move to...
</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="remove">Remove</option>
</select>
</div>
</div>
<div className="book-title">{this.props.book.title}</div>
<div className="book-authors">{this.props.book.authors}</div>
</div>
);
}
}
export default Book;
And the parent component, where method is defined:
// parent component
import React from "react";
import SearchBar from "./SearchBar";
import MainPage from "./MainPage";
import { Route } from "react-router-dom";
import "./App.css";
import * as BooksAPI from "./BooksAPI";
class BooksApp extends React.Component {
constructor(props) {
super(props);
this.moveShelf = this.moveShelf.bind(this);
this.state = {
books: ,
query: "",
searchedBooks:
};
}
componentDidMount() {
BooksAPI.getAll().then(books => {
this.setState({ books: books });
});
}
moveShelf = (book, shelf) => {
BooksAPI.update(book, shelf); //call update method here to stack books
BooksAPI.getAll().then(books => {
//to have books update dynamically -->
this.setState({ books: books });
});
};
updateQuery = query => {
this.setState({
query: query
});
this.updateSearchedBooks(query);
};
updateSearchedBooks = query => {
query
? BooksAPI.search(query).then(searchedBooks => {
/*fetch searchedbooks using the method defined in BooksAPI */
searchedBooks.error
? this.setState({ searchedBooks: })
: this.setState({ searchedBooks });
})
: this.setState({ searchedBooks: });
};
render() {
return (
<div className="app">
<Route
exact
path="/"
render={() => (
<MainPage
books={this.state.books} //calling all my books
moveShelf={this.moveShelf}
/>
)}
/>
<Route
path="/search"
render={() => (
<SearchBar
searchedBooks={this.state.searchedBooks}
moveShelf={this.moveShelf}
/>
)}
/>
</div>
);
}
}
export default BooksApp;
reactjs
add a comment |
I am learning React.
I am working on a Myreads book app project. My app renders fine at the start but the moment I click on the select tag, i get the above error message thrown up.
I thought it was a 'propTypes' issue at first and went ahead and installed prop-types
but it is still not working.
Here is my cmp where there error occurs and my parent cmp where my method is defined:
// child component
import React from "react";
import Icon from "./icons/add.svg";
import SearchBar from "./SearchBar";
class Book extends React.Component {
render() {
return (
<div className="book">
<div className="book-top">
<div
className="book-cover"
style={{
width: 128,
height: 193,
backgroundImage: `${
this.props.book.imageLinks
? "url(this.props.book.imageLinks.thumbnail)"
: "Icon"
}`
}}
/>
<div className="book-shelf-changer">
<select
onChange={event =>
this.props.moveShelf(this.props.book, event.target.value)
}
value={this.props.book.shelf}
>
<option value="move" disabled>
Move to...
</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="remove">Remove</option>
</select>
</div>
</div>
<div className="book-title">{this.props.book.title}</div>
<div className="book-authors">{this.props.book.authors}</div>
</div>
);
}
}
export default Book;
And the parent component, where method is defined:
// parent component
import React from "react";
import SearchBar from "./SearchBar";
import MainPage from "./MainPage";
import { Route } from "react-router-dom";
import "./App.css";
import * as BooksAPI from "./BooksAPI";
class BooksApp extends React.Component {
constructor(props) {
super(props);
this.moveShelf = this.moveShelf.bind(this);
this.state = {
books: ,
query: "",
searchedBooks:
};
}
componentDidMount() {
BooksAPI.getAll().then(books => {
this.setState({ books: books });
});
}
moveShelf = (book, shelf) => {
BooksAPI.update(book, shelf); //call update method here to stack books
BooksAPI.getAll().then(books => {
//to have books update dynamically -->
this.setState({ books: books });
});
};
updateQuery = query => {
this.setState({
query: query
});
this.updateSearchedBooks(query);
};
updateSearchedBooks = query => {
query
? BooksAPI.search(query).then(searchedBooks => {
/*fetch searchedbooks using the method defined in BooksAPI */
searchedBooks.error
? this.setState({ searchedBooks: })
: this.setState({ searchedBooks });
})
: this.setState({ searchedBooks: });
};
render() {
return (
<div className="app">
<Route
exact
path="/"
render={() => (
<MainPage
books={this.state.books} //calling all my books
moveShelf={this.moveShelf}
/>
)}
/>
<Route
path="/search"
render={() => (
<SearchBar
searchedBooks={this.state.searchedBooks}
moveShelf={this.moveShelf}
/>
)}
/>
</div>
);
}
}
export default BooksApp;
reactjs
add a comment |
I am learning React.
I am working on a Myreads book app project. My app renders fine at the start but the moment I click on the select tag, i get the above error message thrown up.
I thought it was a 'propTypes' issue at first and went ahead and installed prop-types
but it is still not working.
Here is my cmp where there error occurs and my parent cmp where my method is defined:
// child component
import React from "react";
import Icon from "./icons/add.svg";
import SearchBar from "./SearchBar";
class Book extends React.Component {
render() {
return (
<div className="book">
<div className="book-top">
<div
className="book-cover"
style={{
width: 128,
height: 193,
backgroundImage: `${
this.props.book.imageLinks
? "url(this.props.book.imageLinks.thumbnail)"
: "Icon"
}`
}}
/>
<div className="book-shelf-changer">
<select
onChange={event =>
this.props.moveShelf(this.props.book, event.target.value)
}
value={this.props.book.shelf}
>
<option value="move" disabled>
Move to...
</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="remove">Remove</option>
</select>
</div>
</div>
<div className="book-title">{this.props.book.title}</div>
<div className="book-authors">{this.props.book.authors}</div>
</div>
);
}
}
export default Book;
And the parent component, where method is defined:
// parent component
import React from "react";
import SearchBar from "./SearchBar";
import MainPage from "./MainPage";
import { Route } from "react-router-dom";
import "./App.css";
import * as BooksAPI from "./BooksAPI";
class BooksApp extends React.Component {
constructor(props) {
super(props);
this.moveShelf = this.moveShelf.bind(this);
this.state = {
books: ,
query: "",
searchedBooks:
};
}
componentDidMount() {
BooksAPI.getAll().then(books => {
this.setState({ books: books });
});
}
moveShelf = (book, shelf) => {
BooksAPI.update(book, shelf); //call update method here to stack books
BooksAPI.getAll().then(books => {
//to have books update dynamically -->
this.setState({ books: books });
});
};
updateQuery = query => {
this.setState({
query: query
});
this.updateSearchedBooks(query);
};
updateSearchedBooks = query => {
query
? BooksAPI.search(query).then(searchedBooks => {
/*fetch searchedbooks using the method defined in BooksAPI */
searchedBooks.error
? this.setState({ searchedBooks: })
: this.setState({ searchedBooks });
})
: this.setState({ searchedBooks: });
};
render() {
return (
<div className="app">
<Route
exact
path="/"
render={() => (
<MainPage
books={this.state.books} //calling all my books
moveShelf={this.moveShelf}
/>
)}
/>
<Route
path="/search"
render={() => (
<SearchBar
searchedBooks={this.state.searchedBooks}
moveShelf={this.moveShelf}
/>
)}
/>
</div>
);
}
}
export default BooksApp;
reactjs
I am learning React.
I am working on a Myreads book app project. My app renders fine at the start but the moment I click on the select tag, i get the above error message thrown up.
I thought it was a 'propTypes' issue at first and went ahead and installed prop-types
but it is still not working.
Here is my cmp where there error occurs and my parent cmp where my method is defined:
// child component
import React from "react";
import Icon from "./icons/add.svg";
import SearchBar from "./SearchBar";
class Book extends React.Component {
render() {
return (
<div className="book">
<div className="book-top">
<div
className="book-cover"
style={{
width: 128,
height: 193,
backgroundImage: `${
this.props.book.imageLinks
? "url(this.props.book.imageLinks.thumbnail)"
: "Icon"
}`
}}
/>
<div className="book-shelf-changer">
<select
onChange={event =>
this.props.moveShelf(this.props.book, event.target.value)
}
value={this.props.book.shelf}
>
<option value="move" disabled>
Move to...
</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="remove">Remove</option>
</select>
</div>
</div>
<div className="book-title">{this.props.book.title}</div>
<div className="book-authors">{this.props.book.authors}</div>
</div>
);
}
}
export default Book;
And the parent component, where method is defined:
// parent component
import React from "react";
import SearchBar from "./SearchBar";
import MainPage from "./MainPage";
import { Route } from "react-router-dom";
import "./App.css";
import * as BooksAPI from "./BooksAPI";
class BooksApp extends React.Component {
constructor(props) {
super(props);
this.moveShelf = this.moveShelf.bind(this);
this.state = {
books: ,
query: "",
searchedBooks:
};
}
componentDidMount() {
BooksAPI.getAll().then(books => {
this.setState({ books: books });
});
}
moveShelf = (book, shelf) => {
BooksAPI.update(book, shelf); //call update method here to stack books
BooksAPI.getAll().then(books => {
//to have books update dynamically -->
this.setState({ books: books });
});
};
updateQuery = query => {
this.setState({
query: query
});
this.updateSearchedBooks(query);
};
updateSearchedBooks = query => {
query
? BooksAPI.search(query).then(searchedBooks => {
/*fetch searchedbooks using the method defined in BooksAPI */
searchedBooks.error
? this.setState({ searchedBooks: })
: this.setState({ searchedBooks });
})
: this.setState({ searchedBooks: });
};
render() {
return (
<div className="app">
<Route
exact
path="/"
render={() => (
<MainPage
books={this.state.books} //calling all my books
moveShelf={this.moveShelf}
/>
)}
/>
<Route
path="/search"
render={() => (
<SearchBar
searchedBooks={this.state.searchedBooks}
moveShelf={this.moveShelf}
/>
)}
/>
</div>
);
}
}
export default BooksApp;
reactjs
reactjs
edited Nov 23 '18 at 14:32
laruiss
2,4591920
2,4591920
asked Nov 23 '18 at 14:15
Afeez JimohAfeez Jimoh
212
212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I guess that you do not pass moveShelf
to Book
inside MainPage
and/or SearchBar
components.
You do not need this.moveShelf = this.moveShelf.bind(this);
when you define it as an arrow function moveShelf = (book, shelf) => {...}
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You needmoveShelf={this.props.moveShelf}
insideMainPage
andSearchBar
:<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448296%2fthis2-props-moveshelf-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I guess that you do not pass moveShelf
to Book
inside MainPage
and/or SearchBar
components.
You do not need this.moveShelf = this.moveShelf.bind(this);
when you define it as an arrow function moveShelf = (book, shelf) => {...}
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You needmoveShelf={this.props.moveShelf}
insideMainPage
andSearchBar
:<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
add a comment |
I guess that you do not pass moveShelf
to Book
inside MainPage
and/or SearchBar
components.
You do not need this.moveShelf = this.moveShelf.bind(this);
when you define it as an arrow function moveShelf = (book, shelf) => {...}
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You needmoveShelf={this.props.moveShelf}
insideMainPage
andSearchBar
:<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
add a comment |
I guess that you do not pass moveShelf
to Book
inside MainPage
and/or SearchBar
components.
You do not need this.moveShelf = this.moveShelf.bind(this);
when you define it as an arrow function moveShelf = (book, shelf) => {...}
I guess that you do not pass moveShelf
to Book
inside MainPage
and/or SearchBar
components.
You do not need this.moveShelf = this.moveShelf.bind(this);
when you define it as an arrow function moveShelf = (book, shelf) => {...}
answered Nov 23 '18 at 14:24
UjinT34UjinT34
2,0191314
2,0191314
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You needmoveShelf={this.props.moveShelf}
insideMainPage
andSearchBar
:<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
add a comment |
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You needmoveShelf={this.props.moveShelf}
insideMainPage
andSearchBar
:<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
<div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.moveShelf} /></div>
– Afeez Jimoh
Nov 23 '18 at 14:29
You need
moveShelf={this.props.moveShelf}
inside MainPage
and SearchBar
: <div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
You need
moveShelf={this.props.moveShelf}
inside MainPage
and SearchBar
: <div className="list-books-content"> <BookShelf books={this.props.books} moveShelf={this.props.moveShelf} /></div>
– UjinT34
Nov 23 '18 at 14:29
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
Thanks Ujin it worked ,really appreciate the help
– Afeez Jimoh
Nov 23 '18 at 14:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448296%2fthis2-props-moveshelf-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown