I create chrome extension in Rect. How can I go, be redirected to another component by pressing the button in react, chrome extension?
How can I go, be redirected from the App
component (after pressing the button) to the ItemDetails
component? Without using conditions (ternary operator).
I found such an article: Routing in Chrome Extension written in React
import { createMemoryHistory } from 'history'
const history = createMemoryHistory()
render() {
let page = null
switch (this.state.page) {
case 'home':
page = <Home />
break
case 'user':
page = <User />
break
}
return page
}
I do not understand this this.state.page
. If I want to go to another component, how can I get this this.state.page
. How do I save the component name in the state it wants to go to?
Code here: https://stackblitz.com/edit/react-be4lpn
import React, { Component } from 'react';
import { render } from 'react-dom';
import axios from 'axios';
class ItemDetails extends Component {
constructor(){
super();
}
render() {
return (
<div>
<p>
Description:vvvvvvvvvvv
</p>
</div>
)
}
}
class App extends React.Component {
constructor() {
super();
this.state = {
items: [
{
name: 'A',
description: 'Hello'
}
],
form: {}
};
}
render() {
return (
<div>
<form action="" method="post" onSubmit={this.onSubmit}>
<button type="submit" value="Submit" >Log in</button>
</form>
</div>
);
}
}
render(<App />, document.getElementById('root'));
from How can I go, be redirected to another component by pressing the button in react, chrome extension?
No comments:
Post a Comment