DEV Community

Discussion on: Hot to call this function from another component in react?

Collapse
 
warriorofsunlight profile image
WarriorOfSunlight

Are you calling this from a functional component or a class component? Where and when do you want to call the component (on mount, after a specific condition, etc.)?

A very generic example of calling a function from JSX

<MyComponent>
   {someCondition ? uCyr() : notUCyr()}
</MyComponent>

A very generic example of calling a function before the return

function MyComponent() {
   uCyr()
   return(
      <OtherComponent />
   )
}

A very generic example of calling a function in useEffect (from react docs)

useEffect(() => {
  const subscription = props.source.subscribe();
  return () => {
    // Clean up the subscription
    subscription.unsubscribe();
  };
});

Helpful links and further reading

reactjs.org/docs/faq-functions.html

reactjs.org/docs/hooks-effect.html

Collapse
 
ivkemilioner profile image
ivkeMilioner • Edited

Call from here import React from "react";
import "./styles.css";
import './Ucyr';

import { Ucyr } from './Ucyr';

export default function App() {

return (









);

}