btholt / btholt/complete-intro-to-react

How to share a state of Landing component into App so that I can distinguish a searchTerm into Search component?

Open
#70 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.1k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Hi,
Can anyone tell me how can I share a state of the Landing component into the App so that I can distinguish a searchTerm in the Search component? Basically, I'd like to make the Landing component working.

This is sth that Brian talks about in the React Wrapper in the chapter 'Data in React' (FEM course).
https://frontendmasters.com/courses/react/wrapper-and-q-a/

I've been trying to refactor Landing.jsx. Now it looks like this:

```
import React, { Component } from 'react';
import { Link } from 'react-router-dom';

class Landing extends Component {
state = {
beforeSearchTerm: ''
};

handleSearchTermChange = (event: SyntheticKeyboardEvent & { target: HTMLInputElement }) => {
this.setState({ beforeSearchTerm: event.target.value });
};

render() {
return (


svideo



Search
or Browse All

);
}
}

export default Landing;
```
Now I want this beforeSearchTerm state send into Search component so I can distinguish searchTerm, maybe sth like this-> if I pass sth in Landing component (beforeSearchTerm) then let Search state be beforeSearchTerm, if I don't pass any value then let Search state be empty string:

```
class Search extends Component {
state = {
searchTerm: beforeSearchTerm ? {`${beforeSearchTerm}`} : ''
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.