Skip to content

Conversation

@yisar
Copy link
Member

@yisar yisar commented Mar 17, 2020

Speculative mode implemention,

import { h, render, createContext, useContext } from 'fre'

const Context = createContext(null)

function App() {
  return <Context.Provider value={count1:1, count2:2}>
    <A/>
  </Context.Provider>
}

function A() {
  // Here accept a selector, the component only rerender when selector value changed
  const count1 = useContext(Context, v=>v.count1)
  return <div>{count1}</div>
}

render(<App />, document.body)

To learn more details, stare at this react pr

@codecov-io
Copy link

codecov-io commented Mar 17, 2020

Codecov Report

Merging #140 into master will decrease coverage by 5.09%.
The diff coverage is 25.92%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #140     +/-   ##
========================================
- Coverage    97.5%   92.4%   -5.1%     
========================================
  Files           7       7             
  Lines         360     382     +22     
  Branches      110     115      +5     
========================================
+ Hits          351     353      +2     
- Misses          8      24     +16     
- Partials        1       5      +4
Impacted Files Coverage Δ
src/index.js 100% <ø> (ø) ⬆️
src/h.js 100% <100%> (ø) ⬆️
src/hooks.js 71.01% <20.83%> (-26.91%) ⬇️
src/reconciler.js 97.76% <50%> (-0.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46214a0...88ef7ef. Read the comment docs.

@yisar
Copy link
Member Author

yisar commented Apr 10, 2020

There is a user land alternative
https://github.com/yisar/fre/blob/master/demo/src/use-context.js
Context is no need implemented build-in fre core

@yisar yisar closed this Apr 10, 2020
@yisar yisar deleted the context branch May 11, 2020 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants