I need to pass a parameter to the common function when my dom is loaded. I can't use useEfect in my case. So I create a function for that. I need to check some parameters' true and if it is true I return true or I return false.
export function validateUser(data) {
if (data==='order/view'){
return true
}
return false
}
export default validateUser();
return (
<div hidden={()=>{validateUser('order/view')}}> Som Data </div>
)
If div returns 'order/view' I need to show my div and if it's not, I need to hide my div in my react site. But My method can't return the parameters that I send it to. If anyone can help me with that question, It really helps.
If I'm understanding your question correctly, you are wanting to call validateUser to conditionally set the hidden prop being passed to the div. Instead of passing an anonymous callback just directly invoke validateUser and pass the return value as the hidden prop value.
export function validateUser(data) {
return data === 'order/view';
}
export default validateUser();
...
return (
<div hidden={validateUser('order/view')}>Some Data</div>
)
or if you really are conditionally rendering some content
return validateUser('order/view') ? (
<div>Some Data</div>
) : null
You can do something like this
const validateUser = data => data === 'order/view'
export const ChildComponent = ({data}) => {
return (
<div hidden={()=>{validateUser(data)}}> Som Data </div>
)
}
const ParentComponent = (props) => {
return <>
<ChildComponent data={props.data} />
</>
}