Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useRef is not working with custom compnents

On custom components, ref needs to be forwarded.

An example would be like:
// inside index.js
return(
<Navbar scrollFunc={scrollToRef} />      
    <Mainlogo ref={mainLogoRef} />
    <Sales  ref={salesRef} />
    <Introduction ref={introductionRef} />
    <Blog ref={blogRef} />
<Footer />
)
// inside Sales.js
const Sales = (props, ref) => (
  <div ref={ref}> // assigns the ref to an actual DOM element, the div
    /* anything you want to render here */
  </div>
)

export default React.forwardRef(Sales);

This is because `ref` is (usually) a reference to a DOM element. 
A React Component can render multiple DOM elements, so you need to be explicit about
where the `ref` should be assigned to.
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript const memory 
Javascript :: how to check jasmine version 
Javascript :: check for changes in other store NUXT JS 
Javascript :: api post to curl command converter 
Javascript :: Make React Tooltip work for dynamic elements 
Javascript :: javascript to typescript converter tool 
Javascript :: js array map and update tat array value 
Javascript :: click outside button angular 
Javascript :: nodejs createwriteStream file image broken 
Javascript :: how-to get selected value of a dropdown menu in reactjs 
Javascript :: Function As Parameter In Self Invoking Function 
Javascript :: python save api response to json file append 
Javascript :: react-spring 
Javascript :: This is the JSON 
Javascript :: Backbone.model first parameter determines properties that each instance must have 
Javascript :: converting jsObject to JSON 
Javascript :: Using strings, the spread operator creates an array with each char in the string 
Javascript :: javascript Least prime factor of numbers till n 
Javascript :: Html() is a JQuery Function 
Javascript :: netsuite get search column value suitescript 
Javascript :: convert array to conventional array js 
Javascript :: broken image 
Javascript :: ajax file upload 
Javascript :: javascript object duplicate keys 
Javascript :: how to create session cookie in node js 
Javascript :: sort array without using sort function in javascript 
Javascript :: forming a magic sqare hackerank in javascript 
Javascript :: lookup objects 
Javascript :: angular date passed to donet care is a day less 
Javascript :: wast node 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =