Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to pass function as a props in react in functional components

function App() {
  const [status, setStatus] = React.useState(false);
  const [text, setText] = React.useState("");
  const handleClick = () => {
    this.setStatus(prev => ({ status: !prev.status }));
  };
  const handleChange = e => {
    this.setStatus({ text: e.target.value });
  };

  return (
    <>
      <button onClick={handleClick}>Open photo entry dialog</button>
      <ChildComponent
        isOpen={status}
        text={text}
        handleChange={handleChange}
        handleClick={handleClick}
      />
    </>
  );
}

const ChildComponent = ({ isOpen, text, handleChange, handleClick }) => {
  return (
    <>
      {isOpen && (
        <Model
          status={isOpen}
          handleClick={handleClick}
          text={text}
          handleChange={handleChange}
        />
      )}
    </>
  );
};
Comment

passing props in react functional components

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

const root = ReactDOM.createRoot(document.getElementById('root'));
const element = <Welcome name="Sara" />;
root.render(element);
Comment

PREVIOUS NEXT
Code Example
Javascript :: ubuntu apps to install 
Javascript :: javascript split method 
Javascript :: common javascript coding interview questions 
Javascript :: how to fetch data from another website in javascript 
Javascript :: flutter inject javascript in flutter webview 
Javascript :: javascript form data 
Javascript :: get last element in array javascript 
Javascript :: currenttarget javascript 
Javascript :: join on JSON field 
Javascript :: eslint disable line 
Javascript :: close jquery 
Javascript :: temporal dead zone in es6 
Javascript :: set a variable in express.js 
Javascript :: how to get lastchar in string in js 
Javascript :: variables dinamicas javascript 
Javascript :: mongodb where field is not equal 
Javascript :: javascript pipe function 
Javascript :: cypress set date to specific date 
Javascript :: passing json as datasource to jasper report library 
Javascript :: make forn awesome icon clickable in react 
Javascript :: Iterate with JavaScript Do...While Loops 
Javascript :: multilone input html 
Javascript :: JavaScript Extract Values 
Javascript :: use the AJAX XMLHttpRequest object in Javascript to send json data to the server 
Javascript :: duplicate text javascript 
Javascript :: percentage with react 
Javascript :: javascript add field to array 
Javascript :: iframe content zoom in and zoom out jquery 
Javascript :: how to select default searchable dropdown value in jquery 
Javascript :: how to use if else statement in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =