Way to Access Const from Another Component in React

Use const from another file in Reactjs

Edit after seeing your response above: If the issue is just that the above code isn't working, here are a couple of things to check.

Inside of ProgressBar you've got a couple of errors in your JSX. First, you need curly braces around your JavaScript interpolation and secondly, you're not returning anything in your .map() function. If you were using parentheses it would be an implicit return, but with the curly braces you need a return statement. Try this instead:

import React from 'react';

const ProgressBar = (props) => {
return ( <div className={props.className}>
<h3> {props.title} </h3>
<div className ="years">
<span> Experiences </span>
{props.levels.map((level) => {
return (<span>{level}</span>)
})
} </div>
)};

How to call a const on another class on React?

You can send the hideWelcome as props and call it in Welcome component from props:

export default function Welcome({ hideWelcome }) {
return (
<Button onClick={hideWelcome} />)
}

export default function Home() {

const hideWelcome = () => {
console.log("Hide Welcome");
};

return (<Welcome hideWelcome={hideWelcome} />)
}

You can destructuring the props object like :

Welcome({ hideWelcome }) 

Or just calling props.hideWelcome


export default function Welcome(props) {
return (
<Button onClick={props.hideWelcome} />)
}

export default function Home() {

const hideWelcome = () => {
console.log("Hide Welcome");
};

return (<Welcome hideWelcome={hideWelcome} />)
}

How to pass a const variable from one component to another react

You should return the apollo client instance in your function and export the createApolloClient.

import { ApolloProvider } from '@apollo/react-hooks';
import ApolloClient from 'apollo-boost';

export const createApolloClient = () => {
return new ApolloClient({
uri: 'http://localhost/headless-cms/admin/',
fetchOptions: {
mode: 'no-cors',
},
});
}

export default CreateApolloClient;
import React from 'react';
import ReactDOM from 'react-dom';
import PageLayout from './components/page-layout'
import {createApolloClient} from './apollo-settings'
import {BrowserRouter} from 'react-router-dom';
import { ApolloProvider } from '@apollo/react-hooks';

const client = createApolloClient();

ReactDOM.render(<ApolloProvider client={client}><BrowserRouter><PageLayout /></BrowserRouter></ApolloProvider>, document.getElementById('site-wrapper'));

React, read const from another component

Import it in your BasicMaintainer file:

import GeneratingUnit, {columns} from "./generating-unit";


Related Topics



Leave a reply



Submit